Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Clearing the Undo Stack in a Macro.
by Allen Wyatt
(last updated October 10, 2015)
In Word, you can use the UndoClear method with the ActiveDocument object in order to clear the Undo stack. If you are programming macros in Excel's flavor of VBA, you may wonder if there is a similar method for use in Excel.
Excel VBA doesn't provide a method like UndoClear. The reason is because the undo stack is automatically cleared by Excel whenever your macro makes a change (any change) to the workbook. If your macro doesn't make any changes, and you still want it to clear the undo stack, then all you need to do is make an innocuous change to the worksheet. For instance, the following macro copies the contents of cell A1 back into A1 and, in the process, clears the undo stack:
Sub ClearUndo() Range("A1").Copy Range("A1") End Sub
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2463) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Clearing the Undo Stack in a Macro.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Do you get tired of the dialog box that says "do you want to enable macros" that is displayed when you open a workbook. You ...Discover More
Need to know the current hour of the day? You can derive the information in your macros by using the Hour function, as ...Discover More
Need to know the character code used for a particular character? In a macro you can use the Asc function to determine the ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.