Macro to make Undo (Ctrl+Z) and Redo (Ctrl+Y)?

cgcamal

Active Member
Joined
May 2, 2007
Messages
472
Hi guys,

I'm trying to use Undo and Redo within a procedure but only works the Undo
and OnUndo nor Repeat seem to work.

I'm trying to do this with the below code:
1- Delete a value in any cell, let say A1 (this is the user action);
2- Run step by step the macro;
3- When Undo line is executed (like Ctrl+Z), Value in A1 appears (as before of step 1 happens);
4- But when OnUndo is executed, nothing happens. The expected result is to go back to step 1 (user action),
when the value was deleted and should disappear again like doing a Ctrl+Y.


Code:
Sub MyMacro()

    Application.Undo [COLOR=Green]'To return before last user action.[/COLOR]
    Application.OnUndo "Undo VB Procedure", "Book1.xlsm!MyMacro" [COLOR=Green]'Expected to return to state of the last action generated by user.[/COLOR]
    Range("A1").Select
End Sub

I don't know if it is possible or I'm only doing it wrong.

Maybe somebody can help me.

Many thanks in advance.

Regards
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Tough question as VBA actions can't be undo. It more like creating a temp file using vba and once completed it saves it to original file.

I have not done this before but would be interested to learn how to do it too.

Biz
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,151
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top