Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Undo changes in range

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Undo changes in range

Dave - works like a charm. Thank you.
Bri


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Undo changes in range

Dave - great advice! I'll be able to incorporate this in my code too.

Would it be difficult to NOT give the warning if the cell is originally
blank? For example, I type 'John' in a blank cell. (no msgbox). Now I
CHANGE it to 'Jon' (msgbox asking for confirmation as in your reply to
Bri).

grateful
anny


"Dave Peterson" wrote in message
...
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Undo changes in range

The bad news is that you could change multiple cells at one time. You could
keep track of the old values and do a comparison. Maybe using a hidden
worksheet that gets populated with the values in that sheet when the workbook
opens???

I put this under the ThisWorkbook module:

Option Explicit
Private Sub Workbook_Open()
Me.Worksheets("sheet1").Cells.Copy
Me.Worksheets("sheet1Mirror").Range("a1").PasteSpe cial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub

Then this goes behind the worksheet with the "monitoring" going on:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim WatchRange As Range
Dim ChangedRange As Range
Dim Resp As Long
Dim myCell As Range
Dim FoundANonBlank As Boolean

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
FoundANonBlank = False
For Each myCell In ChangedRange.Cells
If IsEmpty(Me.Parent.Worksheets("sheet1Mirror") _
.Range(myCell.Address).Value) Then
'do nothing, it was empty
Else
FoundANonBlank = True
Exit For
End If
Next myCell

Resp = vbYes
If FoundANonBlank = True Then
Resp = MsgBox(Prompt:="You changed a cell in the WatchRange" _
& vbLf _
& "Are you sure?", Buttons:=vbYesNo)
End If

If Resp = vbYes Then
'copy value to mirrored sheet
For Each myCell In ChangedRange.Cells
Me.Parent.Worksheets("sheet1Mirror") _
.Range(myCell.Address).Value = myCell.Value
Next myCell
Else
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
End If

End If

End Sub

It seemed to work ok under light testing.

anny wrote:

Dave - great advice! I'll be able to incorporate this in my code too.

Would it be difficult to NOT give the warning if the cell is originally
blank? For example, I type 'John' in a blank cell. (no msgbox). Now I
CHANGE it to 'Jon' (msgbox asking for confirmation as in your reply to
Bri).

grateful
anny

"Dave Peterson" wrote in message
...
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


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Undo changes in range

wow - thanks for all your efforts - works well
anny


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UNDO - not available Chris T-M Excel Discussion (Misc queries) 3 February 17th 09 01:11 AM
Charts forget range or data; fixed by manual alteration then Undo Garth T Kidd Charts and Charting in Excel 1 February 8th 07 03:23 PM
UNDO - how many times can I UNDO? Jane Excel Worksheet Functions 2 May 19th 05 03:03 AM
Why is my undo function in Excel only can undo the last 1 or 2 ch. 1111111111111111111111111111111111111111 Excel Worksheet Functions 1 November 24th 04 11:13 AM
Undo Please? Jerett Excel Programming 2 December 26th 03 09:33 PM


All times are GMT +1. The time now is 08:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"