VBA Break Function: How to Pause or Stop a Running Macro

VBA & macros · Updated November 14, 2026

VBA does not have a built-in Break function or statement. To interrupt a running macro, use the Visual Basic Editor’s Break command or a breakpoint; in code, use Stop to pause execution or an appropriate Exit statement to leave a loop or procedure.

What “Break” means in VBA

People searching for a “Break function” usually want to stop a macro at a particular point, interrupt one that is running, or get out of a loop. These are different tasks, and VBA handles them with different tools. The word Break by itself is not a VBA command you can put into a procedure.

VBA’s debugging tools can put code into Break mode. Execution is paused, and you can inspect variables, step through statements, or continue. Break mode is a state of the editor, not a function call. A breakpoint is a marker that tells the editor to enter that state when execution reaches a chosen line. Stop is a statement in the code that also pauses execution.

This distinction matters when adapting examples from languages such as Python, JavaScript, or C. Those languages may use a break statement to leave a loop. In VBA, use Exit For or Exit Do for that purpose; neither is a general-purpose command to interrupt any running macro.

Interrupt a macro that is running

In Excel for Microsoft 365 on Windows, you can interrupt a running macro with Ctrl+Break. Depending on the situation, Excel may show a dialog that lets you continue, end, or debug the code. You can also switch to the Visual Basic Editor (VBE) and choose Run > Break. The editor then pauses at the current or next interruptible line.

On a Mac, keyboard layouts often do not provide a dedicated Break key, and the available shortcut can depend on the keyboard and Excel version. If the shortcut is unclear or does not work, use the VBE’s Run > Break menu command instead. Excel for the web does not run VBA macros; use the desktop Excel app to run or debug VBA.

An interruption is most useful for a macro that is stuck in a loop or taking longer than expected. Once it pauses, inspect the highlighted line and the values of relevant variables. Choose Run > Reset if you want to abandon the current run and reset the VBA project’s execution state. Resetting is different from continuing: it does not complete the remaining code.

Pause at a chosen line with a breakpoint

A breakpoint pauses a macro when it reaches a particular executable line, without requiring a pause statement to remain in the procedure. In the VBE, click in the line’s margin or place the cursor on the line and press F9. A red marker indicates the breakpoint. Run the macro, and execution stops there so you can examine the state of the program.

To remove a breakpoint, press F9 again on that line or click its marker. To clear breakpoints during debugging, use the VBE’s breakpoint controls or the relevant command in the Debug menu. Menu availability and wording can vary slightly between VBE versions, so the editor’s menus are a reliable reference when a shortcut differs.

Breakpoints are especially useful when a problem occurs after several steps. Rather than pausing at the beginning and stepping through every line, place one just before the suspicious operation. Then use Run > Step Into to execute statements one at a time, or continue running after checking the values. A breakpoint is a development aid; it is not an instruction that end users need to see in the finished workbook.

Use Stop to pause from VBA code

The Stop statement deliberately places VBA in Break mode when execution reaches it. It can help during development when a particular condition deserves inspection. For instance, the following example pauses when a cell in column A contains the word Review:

Sub CheckForReview()
    Dim cell As Range

    ' Pause when a matching value is found.
    For Each cell In ThisWorkbook.Worksheets("Sheet1").Range("A1:A20")
        If cell.Value = "Review" Then
            Stop
        End If
    Next cell
End Sub

Change Sheet1 and the range to match the workbook. When the condition is met, the editor pauses at Stop; choose Continue to carry on with the next statement. If no cell matches, the procedure finishes without pausing. Remove development-only Stop statements before distributing a workbook, or users may encounter an unexpected pause.

Stop is not the same as a normal exit. It pauses the procedure so you can debug it, and execution can generally be continued from the editor. It is not a substitute for a user-facing message, cancellation workflow, or robust error handling. Before running any macro, save a copy of the workbook: VBA changes cannot be undone with Ctrl+Z, and resetting or ending execution does not roll back edits the macro has already made.

Leave a loop or procedure with Exit

If the goal is to stop part of the code normally, use the Exit statement that matches the structure you want to leave. For example, Exit For leaves a For loop, and Exit Do leaves a Do loop. Exit Sub ends the current Sub procedure, while Exit Function ends the current Function procedure.

Here is a loop that stops searching once it finds a match:

Sub FindFirstReview()
    Dim cell As Range

    ' Leave the loop after the first match.
    For Each cell In ThisWorkbook.Worksheets("Sheet1").Range("A1:A20")
        If cell.Value = "Review" Then
            MsgBox "Found Review in " & cell.Address
            Exit For
        End If
    Next cell
End Sub

In this example, Exit For skips the remaining cells in the loop, but execution continues with the statement after Next cell. It does not stop Excel, pause the editor, or end the entire procedure. If you also want to leave the Sub after the match, put Exit Sub after the message. Choose the narrowest exit that describes the intended behavior; that makes the code easier to follow and less surprising.

Stop, End, and Exit are not interchangeable

VBA also has an End statement, but it is not the everyday equivalent of “break.” End terminates VBA execution abruptly and resets module-level variables. It can interrupt other running code in the VBA project, and it bypasses normal cleanup that your code might otherwise perform. Avoid using it as a routine way to exit a loop or respond to a user cancelling an operation.

Use the tools according to their purpose:

  • Stop pauses execution for debugging.
  • A breakpoint pauses at a chosen line without adding a statement to the procedure.
  • Exit For and Exit Do leave the current loop.
  • Exit Sub and Exit Function leave the current procedure.
  • End forcibly terminates VBA execution and is usually inappropriate for ordinary control flow.

Debug a pause and continue safely

When execution pauses, check the yellow-highlighted line, which indicates where the code is stopped or about to execute. The Locals window can show in-scope variables; open it from the VBE’s View > Locals Window menu. You can also hover over a variable in the code window to inspect its current value. Use Run > Continue to resume, or step through the code to see how values change.

If a macro appears to ignore an interrupt, it may be spending time in a long operation or running code that has disabled keyboard cancellation. Excel’s Application.EnableCancelKey property controls how cancellation is handled. The usual xlInterrupt setting permits an interrupt; code that sets the property to xlDisabled prevents the user from interrupting through the normal keyboard method. A macro should not disable cancellation casually, especially if it performs lengthy work.

For a loop that needs to remain responsive, periodically calling DoEvents can give Excel an opportunity to process pending user input and other events. It is not a replacement for sound loop conditions, and using it carelessly can allow other event-driven code to run while the macro is partway through an operation. A safer design is often to make the loop’s stopping condition explicit and provide a controlled way to cancel.

Common problems and misconceptions

  • Typing Break into a procedure: VBA does not recognize it as a built-in statement. Use a breakpoint, Stop, or the appropriate Exit statement.
  • Expecting Ctrl+Z to reverse a macro: Excel’s undo history generally does not undo VBA changes. Save a separate copy before running code that edits data.
  • Confusing a pause with completion: Break mode means execution is suspended, not that the macro completed. Continue or reset deliberately.
  • Using End to leave a loop: It stops all VBA execution rather than just the loop. Use Exit For or Exit Do.
  • Leaving a breakpoint in a shared workbook: A breakpoint is part of the VBA project’s debugging state and can confuse someone opening the code. Remove development markers before handing off the file.

Frequently Asked Questions

Is Break a function in VBA?
No. VBA has no built-in Break function or statement. Use a VBE breakpoint or the Break command to pause execution, Stop to pause from code, or an Exit statement to leave a loop or procedure.

What is the VBA equivalent of break in a loop?
Use Exit For inside a For loop or Exit Do inside a Do loop. These leave the loop and continue with the code after it; they do not pause the macro for debugging.

How do I stop a running Excel macro?
In Excel for Windows, try Ctrl+Break, or switch to the VBE and choose Run > Break. On a Mac, use the VBE menu if the keyboard does not provide a usable Break key. If cancellation is disabled by the code, the usual interrupt may not work.

How do I pause a macro at a specific line?
Set a breakpoint on that line in the VBE, commonly by clicking its margin or selecting it and pressing F9. When the macro reaches the line, execution pauses so you can inspect variables or step through the next statements.

Can I use VBA in Excel for the web?
No. Excel for the web does not run VBA macros. Open the workbook in desktop Excel for Windows or Mac to use VBA; some editor details and keyboard shortcuts differ between those platforms.

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.