Malcolm torishi
Board Regular
- Joined
- Apr 26, 2013
- Messages
- 219
I have the following vba code in a worksheet that when you double click on say the 5th row under the 4th column (D) it deletes everything in that row from the 3rd column (C) to the 1st column (A) and then cuts and pastes the person’s name in the 1st column (A) onto another sheet. Works perfectly.
The problem I have is, I also have the following formula =counta(A5:Ab25) in cell A1 counting the number of people in column A from rows 5 to 25 , and what happens is when I double click on a cell under the 4th column (D) to delete, cuts and paste the person’s name on that row onto my another sheet, it also reduces my range in my =counta formula, so each time I double click on a row under the 4th column my range reduces in size by one to say =counta(A5:A19)
Can anyone explain why and how to keep my formula working by not reducing the range in my counta formula each time I double click
Thank you
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 6/18/2019 3:09 PM EDT
If Target.Column = 4 And Target.Row > 1 Then
Cancel = True
Dim Lastrow As Long
Lastrow = Sheets(4).Cells(Rows.Count, "B").End(xlUp).Row + 1
Target.Offset(, -3).Resize(, 1).Copy Sheets(4).Cells(Lastrow, 2)
Target.Offset(, -3).Resize(, 3).Delete
End If
End Sub
The problem I have is, I also have the following formula =counta(A5:Ab25) in cell A1 counting the number of people in column A from rows 5 to 25 , and what happens is when I double click on a cell under the 4th column (D) to delete, cuts and paste the person’s name on that row onto my another sheet, it also reduces my range in my =counta formula, so each time I double click on a row under the 4th column my range reduces in size by one to say =counta(A5:A19)
Can anyone explain why and how to keep my formula working by not reducing the range in my counta formula each time I double click
Thank you
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 6/18/2019 3:09 PM EDT
If Target.Column = 4 And Target.Row > 1 Then
Cancel = True
Dim Lastrow As Long
Lastrow = Sheets(4).Cells(Rows.Count, "B").End(xlUp).Row + 1
Target.Offset(, -3).Resize(, 1).Copy Sheets(4).Cells(Lastrow, 2)
Target.Offset(, -3).Resize(, 3).Delete
End If
End Sub