Should be straightforward answer...

A

Alex

Hello

If I write VBA code, run the procedure, and then want to
undo what I have just done, how do I do that?

For example, suppose I run the following procedure which
places the value 10 in cell A1 of the activeworksheet.

Sub XYZ ()
Range("A1").Value = 10
End Sub

How can I undo that?

I feel there ought to be an obvious way...but I can't
find it.

Thanks for any thoughts...

Alex
 
F

Frank Kabel

Hi
the Excel build-in functionality dows not work for macros. So you have
to program this on your own within your macro.
 
D

Don Guillett

Should be, but not so easy.
http://tinyurl.com/4pdzk
From a posting by Chip Pearson

Running a VBA procedure clears Excel's undo buffer, effectively
disabling the Undo feature. The closest you can get is to create
a procedure that undoes your primary procedure, and use
Application.OnUndo to put that procedure in the undo buffer.
E.g.,

Sub AAAA()
Application.OnUndo "Undo This", "UndoProc"
End Sub

Sub UndoProc()
MsgBox "Undo code here"
End Sub
 
Top