samuel.nunn
New Member
- Joined
- Feb 22, 2009
- Messages
- 20
My Worksheet_Change macro is running when I don't need it to run. When cell C7 is modified, I want it to delete the modification and display the message "You cannot modify this cell."
It works properly if someone tries to modify that cell. However, it also triggers if someone selects multiple cells (including C7) and hits delete. I don't want it to trigger in this case. After all, there will be nothing in that cell to delete anyways. Is there a workaround? Or at least a way for the message box to not pop up in this case?
Here is my code:
Sam
It works properly if someone tries to modify that cell. However, it also triggers if someone selects multiple cells (including C7) and hits delete. I don't want it to trigger in this case. After all, there will be nothing in that cell to delete anyways. Is there a workaround? Or at least a way for the message box to not pop up in this case?
Here is my code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("C7")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Display a message when one of the designated cells has been
' changed.
' Place your code here.
Application.EnableEvents = False
Range("C7").Clear
Range("C8").Select
MsgBox "You cannot modify this cell."
Application.EnableEvents = True
End If
End Sub