CanUndo Property Example

This example undoes the last action performed or displays a message box if the action cannot be undone.

If Spreadsheet1.CanUndo Then
    Spreadsheet1.Undo
Else
    MsgBox "can't undo last action"
End If