I am in a situation where the columns on one Worksheet
need to track with the rows on another Worksheet
. So, if a user deletes a column (which they must be allowed to do), I need the corresponding row in another worksheet to be deleted. That works fine, and the code below accomplishes the task.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Target.EntireRow.Address Then
Debug.Print Target.Address
Sheet2.Range("A1").Offset(, Target.Row - 1).EntireColumn.Delete
End If
End Sub
However, this same code runs when a user inserts a row, while in fact I need to add a row to Sheet2
in that case. How can I tell if the user is inserting or deleting when a row action is taken?