dannyok90
Board Regular
- Joined
- Aug 30, 2016
- Messages
- 115
Hi All,
Im trying to incorporate an add new row and column funtion in my spreadsheet
How can i get the following bits of code to work independantly of each other?
The first part of the code works fine and adds a new row exactly where i want it but im struggling to get the second add column bit right?
I have used row 1 and numbered them using A1, A1+1, A1+2 etc to determine the last column.
I would like it to copy the last column and insert it then hide the copying column in the same way i did the rows.
Many Thanks
Dan
Im trying to incorporate an add new row and column funtion in my spreadsheet
How can i get the following bits of code to work independantly of each other?
The first part of the code works fine and adds a new row exactly where i want it but im struggling to get the second add column bit right?
I have used row 1 and numbered them using A1, A1+1, A1+2 etc to determine the last column.
I would like it to copy the last column and insert it then hide the copying column in the same way i did the rows.
Many Thanks
Dan
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If (Target.Value = "Double click to add new row") Then
Target.Worksheet.Unprotect ("TG1")
Target.Offset(-1, 0).EntireRow.Copy
Target.Worksheet.Range("A" & Target.Worksheet.Cells(Target.Worksheet.Rows.Count, "B").End(xlUp).Row - 1).Insert
Target.Worksheet.Range("A" & Target.Worksheet.Cells(Target.Worksheet.Rows.Count, "B").End(xlUp).Row - 2).EntireRow.Hidden = False
Target.Worksheet.Protect ("TG1")
Cancel = True
End If
End Sub
____________________________________________________________________________________________________________
Private Sub Worksheet_BeforeDoubleClick2(ByVal Target As Range, Cancel As Boolean)
Dim LastCol As Integer
With ActiveSheet
If (Target.Value = "Double click to add new") Then
Target.Worksheet.Unprotect ("TG1")
Target.Offset(-1, 0).EntireColumn.Copy
Target.Worksheet.Range("A" & Target.Worksheet.Cells(Target.Worksheet.Rows.Count, "B").End(xlUp).Row - 1).Insert
Target.Worksheet.Range("A" & Target.Worksheet.Cells(Target.Worksheet.Rows.Count, "B").End(xlUp).Row - 2).EntireRow.Hidden = False
Target.Worksheet.Protect ("TG1")
Cancel = True
End If
End Sub