VBA Stop Macro

I accidentally created an infinite loop macro. How can I stop the macro from running?

This is a question I get asked quite often. Fortunately, the solution is easy to remember!

How to manually stop your macro

In VBA, you can stop your macro execution manually with the Esc key or by pressing Ctrl+Break.

Here are a couple alternatives if the first two keystroke options fail.

  1. If you’re running a macro that uses a lot of processing power, you may need to repeatedly press the Esc or Ctrl+Break keys before it’s finally recognized.
  2. If your keyboard has a function key, usually labeled Fn, you may have to hit Ctrl+Fn+Break to manually kill your macro.
  3. If none of these options work, your last resort is to kill the Excel application in its entirety. One way to do this is to press Ctrl+Alt+Delete, launch the Task Manager, click “Details” or “Processes” and scroll down until you find Excel. Once you find it, click it and select “End task.” This is certainly not the desired way to stop your macro because you’ll lose all your unsaved work!

Becoming a VBA expert isn't hard
Over 5000 members are improving their VBA skills for free with our email tutorials. Why don't you join them? Our experts share time-saving VBA tips and we'll give you access to our huge macro library - it's sure to speed up your macro development.

I want to get your free VBA material

Stopping an Infinite Loop Demo

Sub InfiniteLoop()
'If you don't want an infinite loop, do not run this macro.
Dim i As Long
    i = i + 1
End Sub

Running the macro above creates an infinite loop. If you’re brave and you want to test out the keystrokes recommended above, now’s your chance.

Let’s try it! Run the macro and try pressing Esc or Ctrl+Break. You should get a dialog box that looks like this:

VBA Stop Macro

All you have to do is click “End” and your macro will stop.


That’s all for today’s tutorial. Short and sweet!

Please share this article with your friends on Facebook,and Twitter. Sharing articles with others is how wellsr.com will continue to grow, so I genuinely appreciate it.

When you’re ready to free up your time in the office, visit my Excel Add-ins page for some powerful automation products.

I hope you’ll reach out to me via my VBA Consulting page if you have an idea for a macro, but you’d like some help.