To interrupt a running Excel VBA loop on Windows, press Ctrl+Break (sometimes labeled Pause/Break); on a Mac, press Command+Period (⌘.). Excel usually offers a choice to end the macro, debug it, or continue. If your keyboard has no Break key, use Run > Break in the Visual Basic Editor.
What the break shortcut does
A break interrupts VBA execution and puts the code into break mode. Excel pauses the macro at a point where it can respond, rather than automatically undoing work already done. This is useful when a loop is taking too long, has stopped making progress, or is repeating unexpectedly.
After an interruption, Excel commonly displays a dialog with options such as End, Debug, and Continue. Choose Debug to inspect the code at the highlighted line, Continue to let it run again, or End to stop the current procedure. The exact dialog wording can vary by Excel version and situation.
A break is not the same as cancelling or rolling back a transaction. If the macro has already changed cells, those changes may remain. Excel macros generally cannot be reversed with Ctrl+Z, so stopping a procedure does not restore the workbook to its earlier state.
Using the shortcut on Windows and Mac
On a standard Windows keyboard, press Ctrl+Break while the macro is running. The key may be marked Break, Pause, or Pause/Break, and on some keyboards it shares a key with another function. Laptop layouts vary: a Break function may require holding Fn, and there is no single Fn combination that works on every make and model.
On Excel for Mac, the usual interrupt shortcut is Command+Period (⌘.). Because Mac keyboards do not normally have a dedicated Break key, this is the shortcut to try first. If the keyboard layout or remote-desktop setup intercepts it, use the Visual Basic Editor menu instead.
- Windows: Ctrl+Break, or the keyboard’s equivalent Break/Pause combination.
- Mac: Command+Period.
- Either desktop version: In the Visual Basic Editor, choose Run > Break.
Excel for the web does not run VBA macros. To interrupt or debug VBA, open the workbook in the desktop Excel application. A workbook can contain macros while being viewed in a browser, but the web app is not a substitute for desktop Excel’s VBA runtime.
Breaking from the Visual Basic Editor
The Visual Basic Editor (VBE) provides a menu option when the keyboard shortcut is awkward or unavailable. In the editor, choose Run > Break while the procedure is running. The VBE is Excel’s built-in environment for viewing and running VBA code; on Windows, Alt+F11 opens or switches to it. On Mac, open the Visual Basic Editor from Excel’s macro or developer tools, then use its Run menu.
Once paused, the editor can show the current execution line. You can examine variable values, use the Immediate window, or step through the remaining code. If you only want the macro to stop, choose End in the interruption dialog. If the code is paused and you need to terminate it from the editor, Run > Reset resets the running procedure.
Break and Reset are not interchangeable. Break pauses execution so that you can inspect or continue. Reset terminates the procedure and clears its current execution state, including local variables. Neither action reverts changes that the procedure already made to cells, files, or other workbook state.
Why an interrupt may seem not to work
A macro may be busy in a long operation, and Excel may not respond to the interrupt immediately. For example, a loop that performs a large amount of work without yielding control can make the application appear frozen. Give the interrupt a moment to register before pressing the shortcut repeatedly; repeated key presses do not make a slow operation safer.
Another possibility is that the macro has changed Excel’s cancellation behavior. VBA’s Application.EnableCancelKey property controls how Excel handles the user’s attempt to interrupt a running procedure. Its normal behavior is to allow an interrupt. Code can instead route the interruption to an error handler or disable keyboard interruption. If a macro deliberately disables cancellation, the usual shortcut may not stop it.
Keyboard focus and hardware can also be the issue. Check that Excel, rather than another application or a remote desktop toolbar, is receiving the keys. On a laptop, consult the keyboard’s documentation for the Break function. If the key combination is uncertain, the VBE’s Run > Break command is a useful alternative when the editor remains responsive.
Make long loops easier to interrupt
When writing a macro that performs a lengthy loop, periodically calling DoEvents lets Excel process queued events, including keyboard input. It does not make a loop faster, and it is not a replacement for sensible loop limits. Calling it at every iteration can add overhead, so a macro may yield every few hundred or thousand iterations, depending on the work involved.
This small example performs a calculation and yields periodically. It does not alter worksheet cells, making it a relatively safe illustration of where the yield belongs:
Sub LongCalculation()
Dim i As Long
Dim total As Double
For i = 1 To 1000000
total = total + Sqr(i)
' Let Excel process pending input periodically.
If i Mod 1000 = 0 Then
DoEvents
End If
Next i
Debug.Print total
End Sub
In the Immediate window, Debug.Print displays the calculated total after the loop completes. While it runs, use the normal interrupt shortcut to stop it. Before running any macro that changes a real workbook, save a copy first: macros cannot be undone with Ctrl+Z, and an interrupted procedure can leave some of its changes in place.
DoEvents has a trade-off: while Excel processes events, a user action or another event procedure may run. In a complex macro, that can create re-entrancy problems—for example, starting the same procedure again before its first run finishes. Use it deliberately, and consider disabling relevant controls or guarding against a second run when the macro’s design requires that.
What to do if Excel is still unresponsive
Try the correct shortcut once and allow Excel time to respond. If the VBE is accessible, choose Run > Break. If the procedure pauses, inspect the highlighted line before deciding whether to continue or end it. A very large calculation, external data operation, or loop with no opportunity to yield may take time before Excel can process the request.
If the editor offers no response and the application remains stuck, force-closing Excel is a last resort, not a clean way to stop a macro. Unsaved workbook changes may be lost, while some already-saved or external changes may remain. After reopening, check the workbook carefully rather than assuming the interrupted macro either completed everything or changed nothing. For future runs, test on a copy and add a clear exit condition or progress checks to long-running code.
Prevent accidental endless loops
An endless loop often comes from a condition that never changes, a counter that is not incremented, or a loop that checks the wrong cell or value. For instance, a Do While loop will continue as long as its condition remains true; if the code inside never changes the value controlling that condition, it has no natural stopping point.
Before running a loop that edits a workbook, check these basics:
- Confirm that the loop variable changes on every pass and that the exit condition can eventually become false.
- Use a realistic upper bound for a
Forloop where one is appropriate. - Test on a saved copy, especially if the loop writes to cells, deletes data, or changes workbook structure.
- For long work, provide progress information or a planned cancellation mechanism rather than relying only on force-quitting Excel.
These checks help distinguish a slow but finite loop from one that cannot finish. If the code is your own, debugging from the highlighted line can reveal whether the counter, condition, or input data is responsible.
Frequently Asked Questions
What is the keyboard shortcut to stop a VBA macro in Excel?
On Windows, use Ctrl+Break. On Mac, use Command+Period. If the keyboard lacks a usable Break key or the shortcut is intercepted, choose Run > Break in the Visual Basic Editor.
How do I stop an Excel VBA loop if my laptop has no Break key?
Try the laptop’s documented Fn combination for Break or Pause, since it varies by model. If you can reach the Visual Basic Editor, use Run > Break there. A Mac user can try Command+Period.
Does Ctrl+Break undo what the macro has already done?
No. It interrupts execution; it does not roll back completed cell edits or other side effects. Save a separate copy before running a macro that changes important data, and inspect the workbook after stopping it.
What is the difference between Break and Reset in VBA?
Break pauses the procedure so you can inspect it or continue. Reset terminates the running procedure and clears its current execution state. Neither option automatically restores changes the macro already made.
Why does Ctrl+Break not stop my macro?
The keyboard may not provide a Break key, Excel may be too busy to process the request immediately, or the code may have altered Application.EnableCancelKey so interruption is handled differently or disabled. Try the VBE’s Run > Break command and check the macro’s cancellation settings.
Related
- Excel Page Break View Without Page Numbers: What to Do
- Excel Page Break Shortcut: Insert, Remove, and Reset
- Excel Page Break View: How to Set Up Printed Pages
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel Macro Filter: How to Automate Data FilteringTo filter a worksheet with a macro, use VBA’s AutoFilter method on a range that includes its header…
- Microsoft Excel VBA For Loops: Syntax and ExamplesIn Microsoft Excel VBA, a For...Next loop repeats instructions a set number of times, while For Each...Next repeats…
- Excel VBA Hyperlinks: Add, Edit, and Troubleshoot ThemIn Excel VBA, add a hyperlink with the Hyperlinks.Add method, specifying the cell or shape to hold it…
- Excel VBA Pivot Table Filter Multiple Values at OnceTo filter a standard Excel PivotTable to several items with VBA, clear the field’s existing filter and set…
- Excel VBA UserForm: Delete a Record by ID with CodeTo delete a record from an Excel VBA UserForm, identify it by a unique ID, ask the user…
- Excel VBA Scroll Bar Form Control: Setup, Uses, and CodeIn Excel for Microsoft 365 on Windows, insert a Form Control scroll bar from Developer > Insert >…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.