Most Valuable Professional

View Jan Karel Pieterse's profile on LinkedIn subscribe to rss feed
Subscribe in a reader

Subscribe to our mailing list

* indicates required

Audit !!!

Check out our RefTreeAnalyser
the ultimate Excel formula auditing tool.


Excel VBA Masterclass (English)
Excel VBA for Financials (Dutch)

Third party tools

Speed up your file

The best tool to optimise your Excel model!

What has changed?

PerfectXL Compare, for Spreadsheet Comparison
This Excel compare tool is fast, reliable, and easy to use. Compare two Excel files now and see for yourself!
Home > English site > Articles > Undo With Excel VBA > Conclusion
Deze pagina in het Nederlands

Creating An Undo Handler To Undo Changes Done By Excel VBA


I have demonstrated a method to add an undo handler to your project. Of course implementing this method means you will have to change existing code that performs actions that may need to be undone later.

The actions the undo handler can undo are limited to changes to properties of objects in general. Things like inserting or deleting sheets, refreshing querytables, updating Pivottables and etcetera, cannot be undone using this technique.


I have prepared a download for you with example code. Find it here.


Since you have managed to reach the end of this article, maybe you would care to write me a small message, expressing your opinion on this article?

Click here to write an email message to me.



Showing last 8 comments of 62 in total (Show All Comments):


Comment by: Jan Karel Pieterse (22-8-2017 16:08:00)

Hi Zara,

Theoretically, yes. See the previous page of this article for an example:


Comment by: warbe (17-7-2018 19:47:36)

I have undertaken the same effort by means of an undo class module which is not only very simple to use but also requires minimum code change.
BeginOfTransaction starts a new collection of changed cells
ChangeInTransaction provided with one or more cells about to be changed saves each cells properties (content, font, and interior)
EndOfTransaction prepares for undo (activates the undo icon)
BackoutTransaction sets all saved cells into their state prior the change. This procedure is invoked through the undo icon by a simple public procedure called OpUnDo.

I am about to publish this implementation here if you dont'mind


Comment by: Jan Karel Pieterse (18-7-2018 10:34:24)

Hi Warbe,

Sounds interesting. I expect this is a lot of code, given that there are a lot of properties to consider!


Comment by: Rich (9-2-2019 18:38:40)

Has there been any further info from Warbe ? on (7/17/2018 7:47:36 PM), he said "I am about to publish this implementation here if you don't' mind " but I don't see any more info on this.

Thanks for a GREAT page!


Comment by: Irian (11-3-2019 17:06:24)

Good afternoon,

thank you for all the hard work you have put into this. However, I can't get it to work.

In you implementation you write: 'If you go for (1), the OnUndo statement can just describe the set of actions done by this routine. Should you prefer to do (2), remember to change the text of the OnUndo statement accordingly.'. Could you emphasise what you mean by this as it is unclear to me what I have to edit in the OnUndo statement.

Also, I have other VBA code running, for instance to change the color of the selected row. Do I have to edit any of that code to work with the undo functionality?

I hope you can help me with this, as it would be a great functionality!

Kind regards,


Comment by: Jan Karel Pieterse (12-3-2019 09:59:44)

Hi Irian,

It means that if you want to enable the user to Undo each VBA change in the reverse order in which they were done, rather than all VBA actions in one step, you will have to update the Undo text after each undo so it states what the next undo would undo. this is done by using the Application.OnUndo statement as shown in the code, but using a different text as its first argument.


Comment by: JON FEENSTRA (18-7-2019 17:50:00)


What is the purpose of the following code in Class Modules(1)?

If mUndoObject Is Nothing Then
End If
If mvNewValue = "" Then
End If
If msProperty = "" Then
End If



Comment by: Jan Karel Pieterse (24-7-2019 13:28:00)

Hi Jon,

I'm afraid I've forgotten. I presume these were there as a placeholder to do checks if the correct information is present when exectuting the change, but I don't recall whether that is correct :-)


Have a question, comment or suggestion? Then please use this form.

If your question is not directly related to this web page, but rather a more general "How do I do this" Excel question, then I advise you to ask your question here:

Please enter your name (required):

Your e-mail address (optional, will only be used to inform you when your comment is published or to respond to your question directly):

Your request or comment (max 2000 characters):

To post VBA code in your comment, use [VB] tags, like this: [VB]Code goes here[/VB].

I give permission to process this data and display my name and my comment on this website accoring to our Privacy Policy.