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!

Write better macros in half the time
I see people struggling with Excel every day and I want to help. That's why I'm giving away my personal macro library for free. This powerful gift lets you automatically import all my macros directly into your spreadsheets with just one click.

I want to join the free wellsrPRO VBA Training program

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, Twitter, and Google+. 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.

About The VBA Tutorials Blog

Ryan Wells

The VBA Tutorials Blog was created by Ryan Wells, a Nuclear Engineer and professional VBA Developer. He created this site to help others learn to write macros in Excel. That's why he developed a unique 3-part free Excel training program to help others quickly learn VBA in a natural setting: right inside Excel.