Undo changes in range
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim ChangedRange As Range
Dim Resp As Long
Set WatchRange = Range("A5:F64")
Set ChangedRange = Intersect(Target, WatchRange)
If ChangedRange Is Nothing Then
MsgBox "You changed a cell NOT in the WatchRange", vbOKOnly
Else
Resp = MsgBox(Prompt:="You changed a cell in the WatchRange" & vbLf _
& "Are you sure?", Buttons:=vbYesNo)
If Resp = vbYes Then
'do nothing
Else
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
End If
End If
End Sub
Bri wrote:
Hello to all
When the user CHANGES an entry in range A5:F64, I'd like a msgbox to ask for
confirmation, or else undo the change.
So far I can tell if the change is in the desired range (see below), but I
have no clue as to how to undo the changes if not confirmed by the user.
Any ideas would be appreciated.
Thanks, Brian
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim ChangedRange As Range
Set WatchRange = Range("A5:F64")
Set ChangedRange = Intersect(Target, WatchRange)
If ChangedRange Is Nothing Then
MsgBox "You changed a cell NOT in the WatchRange", vbOKOnly
Else
MsgBox "You changed a cell in the WatchRange", vbOKOnly
End If
End Sub
--
Dave Peterson
|