I would like to monitor when any of the data in my group of
cells gets modified or deleted.
Here is how my code looks:
Private Sub Worksheet_Change (ByVal Target As Range)
Select Case Target
Case Range("A1")
MsgBox ("A1 was just modified")
Case Range "B1")
MsgBox ("B1 was just modified")
'..... etc. etc.. etc...
Case Range ("M20")
MsgBox ("M20 was just modified")
Case Else
' Do nothing
End Select
End Sub
Does anybody see anything wrong with this approach?? Is my code
correct?? How can I code this in a more efficient manner??
Private Sub Worksheet_Change (ByVal Target As Range)
Select Case Target.value
Case Range("A1").value
MsgBox "A1 was just modified"
Case Range("B1").value
MsgBox "B1 was just modified"
'..... etc. etc.. etc...
Case Range("M20").value
MsgBox "M20 was just modified"
Case Else
' Do nothing
End Select
End Sub
I bet you want:
Private Sub Worksheet_Change (ByVal Target As Range)
Select Case Target.Address
Case Range("A1").address
MsgBox "A1 was just modified"
Case Range("B1").address
MsgBox "B1 was just modified"
'..... etc. etc.. etc...
Case Range("M20").address
MsgBox "M20 was just modified"
Case Else
' Do nothing
End Select
End Sub
Or Private Sub Worksheet_Change (ByVal Target As Range)
Select Case Target.address
Case "$A$1"
MsgBox "A1 was just modified"
Case "$B$1"
MsgBox "B1 was just modified"
'..... etc. etc.. etc...
Case "$M$20"
MsgBox "M20 was just modified"
Case Else
' Do nothing
End Select
End Sub