To set a breakpoint in Excel VBA, open the Visual Basic Editor (press Alt+F11), open the code module you want to inspect, click in the gray margin to the left of a line of code, and a dark red dot appears on that line and the line is highlighted red. Run your macro (F5 or the Run button) and execution stops on that line before it runs. From there you can step through line by line with F8, inspect values by hovering over variables, or press F5 again to continue. A breakpoint is simply a marker that tells VBA "pause here so I can look at what is going on" — it does not change your code and it disappears from the running macro as soon as you stop it.

Breakpoints are the fastest way to answer questions like "why is this cell not updating?" or "what value does this variable actually hold at this point?" Inserts a pause without editing your code, which matters because adding temporary MsgBox lines often changes behavior and has to be cleaned up afterward. Note that menu and dialog labels vary slightly between Excel versions, so if a name in the steps does not match exactly, look for the equivalent item.

What You'll Need

  • A desktop copy of Excel on Windows or Mac with a saved workbook. Breakpoints are set in the Visual Basic Editor, which is not available in Excel for the web or in the mobile apps, so on those platforms you cannot set a breakpoint at all.
  • A macro or VBA procedure to run. If the code is in a workbook you just received, enable macros through the yellow security bar or File > Options > Trust Center before the editor will permit it to run.
  • Macros allowed to run on your machine. If macros are disabled by policy in your organization, the debugger will not execute — ask your IT administrator.

Step-by-Step

  1. Open the Visual Basic Editor. In Excel, press Alt+F11 (on a Mac, Option+F11, or use Tools > Macro > Visual Basic Editor). A separate editor window opens.
  2. Find your module. In the Project Explorer pane on the left, expand your workbook (labeled VBAProject plus the file name), expand Modules or the relevant object like Sheet1 or ThisWorkbook, and double-click the module containing the procedure you want to debug. If Project Explorer is hidden, show it with View > Project Explorer.
  3. Place the cursor in the code. Click inside the procedure that will run. Everything you set in the next step belongs to that procedure's execution.
  4. Click the gray margin next to a line. In the narrow gray strip to the left of the code text, click beside the line where you want execution to pause. A dark red dot and a highlighted red line appear. That is your breakpoint. Pick a line that actually executes, such as a statement that assigns a value or changes a cell — not a blank line, a comment line (starting with an apostrophe), a Dim declaration, or the Sub/End Sub lines.
  5. Set more than one if you need to. Repeat the click on other executable lines. You can have several breakpoints in the same procedure; each is independent.
  6. Run the macro. Press F5, or use Run > Run Sub/UserForm. If the procedure expects arguments and cannot be run on its own, run the macro that calls it instead (see the tips below). Excel pauses on the first breakpoint hit: the line is highlighted in yellow and the caption of the editor title bar reads something like [break].
  7. Inspect the state. Hover the mouse over a variable to see its current value in a tooltip. Open View > Locals Window to list every variable in the current procedure and its value, and View > Immediate Window to type a question such as ?Range("A1").Value and press Enter to print the result.
  8. Step through the code. Press F8 to run one line at a time, F10 to step over a called procedure, or Shift+F8 to step out of the current one. Watch values change as you go — this is usually where the bug becomes obvious.
  9. Continue or stop. Press F5 to run to the next breakpoint or to the end. Press the Reset button (the blue square on the toolbar) or use Run > Reset to stop execution entirely. Reset discards the paused state; to keep inspecting, use the Immediate Window or watch values before you reset.
  10. Remove the breakpoint when finished. Click the red dot again, or place the cursor on the line and press F9. Use Ctrl+Shift+F9 to clear every breakpoint in the project. Forgetting to remove them is the most common reason people later complain that "Excel has frozen" — it has not; it is sitting waiting at a breakpoint. Breakpoints are not saved with the workbook, so they disappear when you close Excel, but they can persist for your whole session.

Common Mistakes

  • Clicking a comment instead of code. The margin shows a dot, but execution never stops there because comment lines do not run. Shift the breakpoint onto the nearest executable statement.
  • Setting a breakpoint in a procedure that never runs. If your macro calls a helper routine, put the breakpoint inside the helper. If nothing seems to happen, add one in the top-level Sub to confirm which path is taken.
  • Expecting breakpoints in a workbook opened read-only or from email. Open a copy you can edit, and make sure macros are enabled so the code can run at all.
  • Forgetting about the paused state. A paused macro blocks Excel from responding normally. If Excel seems unresponsive, switch to the VBA Editor window and look for the yellow highlighted line; press F5 or Reset.
  • Using a breakpoint on code triggered by events. Code in ThisWorkbook or a worksheet module runs on actions like opening the file or changing a cell; set the breakpoint, then trigger the action in Excel to hit it.

Tips

  • F9 toggles a breakpoint on the current line — quicker than aiming at the margin once your cursor is placed.
  • Use Debug > Add Watch to stop whenever a specific variable changes its value or meets a condition, rather than picking a line by eye. This is invaluable in loops where the problem occurs on an unknown pass.
  • In a loop, put a breakpoint just after the loop line and press F8 repeatedly to walk through iterations while watching the Locals Window.
  • If a procedure takes arguments, right-click it in the editor and choose Run Sub/UserForm, or write a tiny calling sub in the Immediate Window by typing its name and arguments and pressing Enter. Running the caller preserves the real argument values.
  • Breakpoints are session-only. If you need to pause at the same place every time, use Stop as a code statement — but delete it before distributing the file, because users will meet the debugger.

Troubleshooting

  • The margin click does nothing. You may be in a form's design view rather than a code module, or the line is not executable. Open a standard code module and try an assignment line.
  • The code runs straight past your dot. Confirm the running macro actually reaches that module. Use View > Call Stack while paused to see the call path; if the procedure is not in the stack, it never ran.
  • Nothing happens when you press F5. If the code errors before reaching your breakpoint, VBA shows an error dialog instead — select Debug on the dialog to land in a paused state at the failing line.
  • You get a message about macros being disabled. Enable macros, and confirm Excel's Trust Center is not blocking the file's location. In managed environments, a policy may prevent this and only IT can change it.
  • Excel is unresponsive after running. Check the VBA Editor for a paused line and press F5 to finish or Reset to stop. If no debugger line exists, save your work, close Excel, and reopen — the breakpoints will be cleared too.

Frequently Asked Questions

Does setting a breakpoint change my macro?

No. It pauses execution in the editor only and is not saved in the workbook's code. Your users will never see it.

Can I set a breakpoint in Excel for the web or on a phone?

No. The Visual Basic Editor and VBA debugging tools exist only in the desktop version of Excel, on Windows and Mac.

Why is my line highlighted yellow instead of red?

Red with a dot is a breakpoint ready to hit; yellow means execution is currently paused on that line. Press F8 or F5 to continue.

How do I remove all breakpoints at once?

In the editor, press Ctrl+Shift+F9, or use the Debug menu's clear-all-breakpoints command, whose exact name varies by version.

What is the difference between a breakpoint and Stop?

A breakpoint is a marker in the editor that lasts only for your session. Stop is a line of code that pauses every time it runs, for anyone — remove it before sharing the file.