I have recorded a macro to delete a number of cells.
I then want to check some totals then undelete those cells.
However, Ctrl Z doesn't work.
Why? Surely the macro just automates a task that could normally be undeleted.
Any workaround?
I ask because the only way I can find is to save the workbook before running the macro then closing without saving, after I've done my thing.
Replies (5)
Please login or register to join the discussion.
What you need
Is an autorun macro that deletes the entire spreadsheet. Save it. Test it. Then you can just reopen it after it has deleted itself.
I assume
you are using a macro in this instance to ease the selection of cells? If so, how about restricting the macro to just the selection process and then use the delete button and undo?
or save the sheet first
You could have the macro save the sheet first, then reopen it afterwards.
Use the macro recorder to generate the code for saving and reopening the sheet and then paste it around your existing code.
It will look something like:
ActiveWorkbook.Save
myworkbook = ActiveWorkbook.FullName
<existing macro code>
Workbooks.Open Filename:=myworkbook, UpdateLinks:=3
As far as I am aware there is no 'macro undo'.
I wonder if ...
... using "Sendkeys" (ugh!) to undertake the deletion would preserve the undo facility? Not tried it. Doubt that it would work.
With kind regards
Clint Westwood
How about
copying the sheet. Making the deletions on the copied sheet and then deleting the copied sheet manually
' Code starts
Sheets("Sheet1").Select
Sheets("Sheet1").Copy Before:=Sheets(1)
Range("Annn:Dnnn").Select
Selection.ClearContents
Range("Ennn:Fnnn").Select
Selection.ClearContents
' etc to delete the cells
' Code ends
Might work depending upon other links within the sheet you're copying