I'm using Worksheet_Change in my Worksheet to react to the changes made by the user, but how do I know if the user just inserted a new row?
Or is there any on_row_change event or something like that?
execute code when row is inserted
-
-
-
-
It seems it wasn't as easy as I thought. Finally I found this script which detects if a row is inserted or deleted:
Code
Display MorePrivate Sub Worksheet_Change(ByVal Target As Range) Static lastValue As Variant Static lastRow As Long Dim lastVal As Variant Dim lastRw As Long lastRw = Cells(65536, 1).End(xlUp).Row lastVal = Cells(lastRw, 1).Value If lastRw = lastRow Then lastValue = lastVal Exit Sub Else If lastVal = lastValue Then Worksheets("Hoja2").Range("A1").Value = 1 MsgBox "You aren't permitted to insert or delete rows within the dynamic range. Please undo any row insertions!" Application.EnableEvents = False Application.Undo Application.EnableEvents = True Else lastValue = lastVal lastRow = lastRw End If End If End Sub
Thank's anyway
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!