How to programmatically code an ‘undo’ function in Excel-Vba? [duplicate]

Add the command button to the worksheet and assign the following macro to it:

Sub UndoLastAction()

    With Application
        .EnableEvents = False
        .Undo
        .EnableEvents = True
    End With

End Sub

It can only undo the last action taken by the user and cannot undo VBA commands.

EDIT: If you need further undo capabilities see:

Undo With Excel VBA – JKP

Leave a Comment