Excel VBA: How to Stop a Running Macro

VBA & macros · Updated November 19, 2026

To stop a running Excel VBA macro on Windows, press Ctrl+Break; on a Mac, press Command+period (.). If Excel does not respond to the interrupt, switch to the Visual Basic Editor and choose Run > Break, or use its Reset button as a last resort; save a copy of the workbook before running macros because Ctrl+Z cannot undo their changes.

Fast ways to interrupt a macro

When a macro is actively running, the keyboard interrupt is usually the quickest option. On Windows, press Ctrl+Break. Some laptop keyboards do not have a dedicated Break key, so you may need a manufacturer-specific combination involving Fn, Pause, or another key. On Mac, try Command+period. If the shortcut does not work, use the Visual Basic Editor’s Run menu to issue a break.

Excel may show a dialog saying that code execution has been interrupted. Choose End to stop the procedure, or Debug to pause at the line that was executing and inspect the code. The exact dialog can depend on how the macro handles errors. If you choose Debug, Excel is paused, not finished: use the editor’s Reset command if you want to terminate the code rather than step through it.

A shortcut may appear ineffective if Excel is busy inside a long operation that does not yield control, if the keyboard maps Break differently, or if the macro has disabled interrupts. Give Excel a moment, try the relevant editor command, and avoid repeatedly clicking or typing into a workbook that is still processing.

What Break and Reset actually do

A break pauses VBA execution at or near its current instruction. In the Visual Basic Editor, you can inspect the highlighted line and variables, then continue, step through the procedure, or reset it. Pausing is useful when you need to understand what the code is doing; it does not automatically restore the workbook or application to its earlier state.

Reset terminates the running VBA project and clears its current execution state, including local variables. In the Visual Basic Editor, use Run > Reset or click the square Reset button on the toolbar. Reset is more forceful than a normal exit from a procedure: code after the reset point will not run. That means cleanup instructions may be skipped, which can leave Excel settings such as events or screen updating in an inconvenient state.

Neither Break nor Reset reverses edits the macro has already made. VBA procedures generally cannot be undone with Excel’s Undo command, and running a macro may clear the ordinary undo history. Check the workbook after stopping, and restore affected data from a saved copy or another reliable source if needed.

Stop a macro from the Visual Basic Editor

On Windows, open the editor with Developer > Visual Basic, or press Alt+F11. On Mac, use Developer > Visual Basic; keyboard shortcuts can depend on the keyboard and system settings. In the editor, choose Run > Break to pause execution. Choose Run > Reset to terminate it. If Excel is paused on a highlighted line, Reset is often the clearest way to end the procedure.

Use Break first if you want to see where execution stopped or find the cause of a hang. After the pause, the editor can show the active procedure and line. Use Reset if you are certain you do not want to resume. If the editor itself is hidden behind Excel, switch between open applications or use the task switcher rather than assuming the macro has stopped.

For a macro that is frozen in a long calculation or external call, the editor may also be unable to respond immediately. Wait briefly for Excel to regain control, then try the interrupt again. Force-quitting Excel should be a last resort because unsaved workbook changes may be lost, and a partially completed macro may already have changed files or data outside the workbook.

Build a cooperative stop into a long macro

For lengthy loops, a designed cancellation check can be more predictable than relying on a keyboard interrupt. The following example checks a cell every 100 rows. Put the word STOP in Z1 on the worksheet named Data while the macro is running. The DoEvents call briefly gives Excel a chance to process user input, so the macro can notice the change. Save a copy of the workbook before running it.

Sub ProcessRowsWithStopCheck()
    Dim ws As Worksheet
    Dim r As Long
    Dim lastRow As Long

    Set ws = ThisWorkbook.Worksheets("Data")
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    For r = 2 To lastRow
        ' Check the stop cell periodically, not on every row.
        If r Mod 100 = 0 Then
            DoEvents
            If UCase$(Trim$(CStr(ws.Range("Z1").Value2))) = "STOP" Then Exit For
        End If

        ' Replace this comment with the row's processing steps.
    Next r
End Sub

This example only checks at each 100-row interval, so it may finish some additional work after STOP is entered. It also assumes the worksheet is named Data and that column A identifies the last row. Change those details to match the workbook. DoEvents lets Excel respond while the macro is running, but it can also allow other events or user actions to occur; keep the interval sensible and avoid exposing the workbook to conflicting edits.

For a simpler procedure, use a normal control-flow statement when a condition is met. Exit For leaves the current loop, while Exit Do leaves a Do loop and Exit Sub leaves the current Sub procedure. Those statements let the code follow its intended exit path, unlike an abrupt reset. They do not roll back changes already made.

Use Exit Sub rather than End

VBA’s End statement stops execution immediately, but it is rarely the right way to provide a Stop option. Abruptly ending code can bypass cleanup and leave application-wide settings changed. Prefer an ordinary exit such as Exit Sub, or leave a loop with Exit For or Exit Do. Structure the procedure so that all exit paths reach any cleanup code.

For example, a macro may turn off screen updating to run more smoothly and then turn it back on. If the procedure is reset before that second instruction runs, Excel can appear not to refresh normally. The same concern applies to settings such as Application.EnableEvents and calculation mode. Before changing such settings, record their original values and restore them in a cleanup section that runs on both normal completion and handled errors.

When a user presses the interrupt key, VBA can raise error 18, “User interrupt occurred.” A procedure can handle that specific error if it needs to perform cleanup or show a message, but broad error handling should not silently hide unrelated problems. A safer design distinguishes an intentional cancellation from other errors and ensures cleanup happens in either case.

Why the stop shortcut may not work

Excel can only act on an interrupt when it gets a chance to process it. A tight loop that never yields, a long calculation, or a call into an external component can delay the response. Adding occasional DoEvents to a loop may improve responsiveness, but it should be used thoughtfully because it allows Excel to process other pending actions while the procedure is partway through its work.

A macro can also set Application.EnableCancelKey to control how Excel handles cancellation. The usual setting, xlInterrupt, allows the user to interrupt execution. Code that sets the property to xlDisabled suppresses that route, so a keyboard interrupt will not behave as expected. Avoid disabling cancellation for long-running procedures; if a special case requires it, restore the normal behavior reliably.

Finally, a macro may have finished even if the workbook looks unchanged, or it may be waiting on an input box, a file operation, or a dialog hidden behind another window. Check for open dialogs and look at Excel’s status before repeatedly interrupting. If a procedure is waiting for user input, respond to or dismiss the dialog rather than treating it as a frozen loop.

Recover safely after stopping

After you stop a macro, check whether Excel has returned to its normal state. Confirm that the workbook responds, that expected sheets and data are present, and that application behavior such as screen refresh and event-driven features still works. If calculation seems stuck in manual mode, inspect Formulas > Calculation Options and restore the setting appropriate for the workbook. Do not change settings blindly if the file relies on a particular calculation mode.

If the procedure changed data before it stopped, compare the result with a saved copy. Ctrl+Z is not a reliable recovery method for macro actions. For important work, keep a backup, use version history where available, or have the macro write results to a separate sheet or file until they are ready to replace original data.

If Excel must be closed because it will not respond, use the operating system’s force-quit option only after giving it time to recover. Unsaved changes can be lost. When Excel opens again, check for a Document Recovery pane or recovered files, but do not assume that recovery contains every change made before the interruption.

Prevent accidental long runs

Before launching an unfamiliar macro, read its purpose and check whether it loops over a large range, opens files, or changes workbook-wide settings. Run it on a copy first. If you wrote the code, test it on a small sample and include a clear stopping condition, progress indication, and cleanup path. A loop should have a condition that eventually becomes false, and calculations based on a last-row value should use the intended worksheet.

Macros can make substantial changes quickly, including deleting or overwriting cells. Only enable macros in files from sources you trust, and do not use a stop shortcut as a substitute for reviewing what a macro does. For a recurring process, a confirmation prompt before destructive changes and a separate output sheet can reduce the cost of an accidental run.

Frequently Asked Questions

Can I stop an Excel macro with Esc?
Sometimes, depending on how the code is written and Excel’s cancellation setting. On Windows, Ctrl+Break is the standard interrupt to try; on Mac, try Command+period. If those do not work, use Run > Break in the Visual Basic Editor.

Does Ctrl+Z undo a macro?
No. Excel’s Undo command generally does not reverse VBA changes, and running a macro can clear the undo history. Save a copy before running code and use that copy or another backup to recover overwritten data.

What is the difference between Break and Reset in VBA?
Break pauses the code so you can inspect or resume it. Reset terminates the running project and clears its execution state. Reset can skip cleanup code, so check Excel’s settings and workbook after using it.

Why does Excel say “Code execution has been interrupted”?
Excel received a cancellation request, such as Ctrl+Break. Choose End to stop the procedure or Debug to pause at the interrupted line. If you choose Debug, use Reset when you want to terminate rather than continue.

How do I add a Stop option to my macro?
Add a cancellation check inside long loops, such as checking a designated worksheet cell periodically and exiting the loop when it contains a stop value. DoEvents can let Excel process that change, but it also allows other pending actions to run, so use it deliberately.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.