After the execution of a macro in Excel, there's no button to revoke it, unless you close the book and choose not to save it.
Is there a neat and easy way to just revoke it?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
The short answer is you can't Undo (I assume this is what you mean by revoke) the actions of a macro. The decisions that take place inside the programming language could be troublesome for Excel to reverse, so there is a blanket "Can't Undo" state induced by kicking off the macro.
The long answer is that if you anticipate Undo being required, your code should accommodate that request by storing the previous state of the data before execution. This is a very broad assumption that you are working with data in VBA; direct file creation and manipulation could be trickier depending on what's executed.
John Walkenbach gives a good example of storing data to provide a future Undo facility:
Computer users are accustomed to the ability to "undo" an operation. Almost every operation you perform in Excel can be undone. If you program in VBA, you may have wondered if it's possible to undo the effects of a subroutine. The answer is yes. The qualified answer is it's not always easy.
I think his opening statement is a little misleading though: for non-coding users the answer is "no, you can't undo a macro".
Yes you can undo all actions of a macro. This is a macro below assigned to a do a DO button.
Sub do_while() Dim num As Integer num = 1 Do While num <= 12 Cells(num, 1) = num num = num + 1 Loop End Sub The code below is assigned to an UNDO button.It uses ClearContents. Dim num As Integer num = 1 Do While num <= 12 Cells(num, 1).ClearContents num = num + 1 Loop End Sub
Use clear contents.