Im trying to add formula to a range if rows are added or deleted.
I found the code below, in which the idea is to name a cell to RowMarker and track its changes. (for example A10000 name = RowMarker, if the row changes, the code is activated).
Determine whether user is adding or deleting rows > Link to where i took the code from.
Why is my code below not performing anything?
Private Sub Worksheet_Change(ByVal Target As Range)
Static lngRow As Long
Dim rng1 As Range
Set rng1 = ThisWorkbook.Names("RowMarker").RefersToRange
Debug.Print Rowmarker
If lngRow = 0 Then
lngRow = rng1.Row
Exit Sub
End If
If rng1.Row = lngRow Then Exit Sub
If rng1.Row < lngRow Then
Application.EnableEvents = False
Range("AB5").Formula = "=IF(SUM(AC15:AT15)>0,SUM(AC15:AT15),"""")"
Application.EnableEvents = True
Else
Application.EnableEvents = False
Range("AB5").Formula = "=IF(SUM(AC15:AT15)>0,SUM(AC15:AT15),"""")"
Application.EnableEvents = True
End If
lngRow = rng1.Row
End Sub