Home > Back-end >  Worksheet Change Event Non Contiguous Range
Worksheet Change Event Non Contiguous Range

Time:01-27

I am trying to write for a worksheet change event for two non contiguous range , which are cells A&lastrow and C&lastrow. For example, if lastrow=5, then it is A5, and C5, while excluding B5. This is my code, and it is not working, any idea on how to fix the syntax.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastrow As Long
lastrow = 5

If Not Intersect(Target, Range("A & lastrow, C & lastrow ")) Is Nothing Then
MsgBox "Hello"

End If
End Sub

CodePudding user response:

Within Mathieu Guindons code snippet there are too many quotation marks.

This works code shows the msgbox when cell A5 or C5 are changed

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastrow As Long
lastrow = 5

If Not Intersect(Target, Me.Range("A" & lastrow & ", C" & lastrow)) Is Nothing Then
    MsgBox "hello"
End If

End Sub
  • Related