Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA Breakpoints Not Working? Fix Debugging Fast

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

If your Excel VBA breakpoints are not working, the most common cause is that the code never actually stops because Excel is still running an older, cached version of your macro, or because a WorkBook_Open routine or an EnableEvents/screen-updating issue is taking a different path than you expect. The quick fix is to press Ctrl+Break to interrupt any running code, click Reset (the square Stop button) on the VBA toolbar, reopen the project, and set the breakpoint again on a line that actually executes. If that does not help, work through the checks below in order.

A breakpoint is the red dot you click in the grey margin of the Visual Basic Editor (VBE). When Excel reaches that line, execution pauses and the line turns yellow. When that behaviour disappears, it is almost always a state problem, a compilation problem, or a settings problem, not a broken installation.

What You'll Need

  • Excel on Windows or Mac, with access to the Visual Basic Editor (Alt+F11 on Windows, Option+F11 on Mac). Labels and menu names can differ slightly by version, edition and region, so look for the closest match if a wording does not appear exactly as written here.
  • The workbook containing the macro, saved as .xlsm or .xlsb. Breakpoints cannot be set in a read-only file or in a workbook opened from a trusted location in a way that blocks editing.
  • Macro security set to allow macros to run (File > Options > Trust Center > Trust Center Settings > Macro Settings on Windows; Excel > Preferences > Security on Mac).
  • Permission to edit the VBA project. If the project is password-protected, you need the password before you can debug it.

Step-by-Step

  1. Stop any running code first. If a macro is still executing, breakpoints behave unpredictably. Press Ctrl+Break (Windows) or Command+Period (Mac), or click the Reset button on the VBE toolbar. The toolbar square turns from a pressed state back to normal when code has stopped.
  2. Confirm you are editing the same project that runs. In the Project Explorer (View > Project Explorer), check the workbook name and module name. A very common trap is having two copies of the workbook open, or a Personal.xlsb macro running instead of the one in front of you. Close duplicate workbooks.
  3. Verify macros are actually enabled for this file. If the yellow security bar appeared when you opened the file and you clicked Disable Content, no code runs at all. Close the workbook, reopen it, and click Enable Content. Check File > Info for any blocked-content notice.
  4. Set the breakpoint on executable code, not on a declaration. Click in the grey margin next to a line that actually does something, such as Range("A1").Value = 1. You cannot pause on Dim, Option Explicit, a comment line, a blank line or a Sub/Function header in the way you expect. If the red dot refuses to appear, the line is not executable.
  5. Force a recompile. In the VBE choose Debug > Compile VBAProject. If a compile error appears, fix it first: Excel will not honour breakpoints in a project that fails to compile, and it may simply run older compiled code instead. Repeat until Compile is greyed out with no error dialog.
  6. Check the code path really reaches your line. Add a temporary MsgBox "reached" one line above the breakpoint and run the macro. If the message never appears, your line is being skipped by an If/Else branch, an early Exit Sub, an error handler, or because the event that should trigger the macro never fires. Move the breakpoint to the first line of the Sub and step through with F8.
  7. Disable error trapping that hides the pause. In the VBE, open Tools > Options > General and look at the Error Trapping setting. Some workbooks install their own On Error Resume Next or a custom error handler that swallows problems and jumps straight to the end. Search the module for On Error and comment out On Error Resume Next temporarily so errors surface.
  8. Turn off event suppression during debugging. If a macro sets Application.EnableEvents = False and then hits an error before restoring it, event-driven code such as Worksheet_Change will not run, and your breakpoint inside that event will never be hit. In the Immediate Window (View > Immediate Window) type Application.EnableEvents = True and press Enter. Do the same with Application.ScreenUpdating = True if the screen looks frozen.
  9. Clear all breakpoints and re-add them. Choose Debug > Clear All Breakpoints, then set yours again. Stale breakpoints survive odd state changes and can appear set while not firing. Closing and reopening the workbook also flushes the compiled project; breakpoints are not saved with the file, so you will re-add them.
  10. Recreate the compiled state cleanly. Save and close the workbook, close Excel entirely, reopen the file, enable macros, then open the VBE and set breakpoints before running anything. If the breakpoint still will not stop, copy the module code into a new module in a new .xlsm workbook to see whether the problem follows the code or the file.

Common Mistakes

  • Setting a breakpoint in a module that is not the one being called, for example editing Module1 while the button runs code in Module2.
  • Clicking the margin on a line inside a With block or an empty If body, where nothing executable exists.
  • Leaving On Error Resume Next active from earlier debugging, so errors and pauses are silently skipped.
  • Forgetting that breakpoints are removed when the project is reset, when the file is closed, and when VBA is recompiled, then assuming they stopped working.
  • Debugging a workbook opened read-only from email or a network share, where the editor may not attach to the running copy.
  • Running the macro from a different workbook's button, add-in or the Quick Access Toolbar, so the code you are watching is not the code that runs.

Tips

  • Use F8 (Step Into) rather than a breakpoint when you want to follow the first pass through a routine, and Ctrl+Shift+F8 (Step Out) to finish the current procedure.
  • Use Debug > Add Watch on a variable to pause automatically when an expression changes or becomes True, which is more reliable than a breakpoint in loop-heavy code.
  • Prefer Debug.Print to the Immediate Window over MsgBox for tracing inside loops, because it does not interrupt execution.
  • Keep Require Variable Declaration on (Tools > Options > Editor) so typos surface at compile time instead of causing silent wrong-branch behaviour.
  • When debugging event code, trigger it manually from the Immediate Window, for example by changing a cell while the editor is open, so you control the timing.
  • Test in a copy of the workbook. Stepping through code that writes to cells or sends email will actually perform those actions.

Troubleshooting

If the red dot appears but execution never pauses, the line is not being reached: add a MsgBox marker and work backwards through the procedure. If the whole VBE seems unresponsive, a modal dialog may be hidden behind the Excel window; press Escape, then check the Windows taskbar for a waiting message box. If Debug > Compile reports an error you cannot locate, use the highlighted line it selects and fix that first, because a project that will not compile cannot be stepped through reliably.

If breakpoints work in a blank workbook but never in yours, suspect the file itself: open it with macros disabled, copy the modules to a new .xlsm file, and test there. Corrupted projects behave exactly like this, and rebuilding is often faster than hunting the cause. If macros are disabled by policy in a managed environment, the editor may open but never run your code at all; in that case contact whoever administers the machine, as this is not something to work around.

On Mac, the VBE has fewer facilities than the Windows version and some keyboard shortcuts differ. If you cannot pause at all, check that the workbook is not in a protected view equivalent and that macros are permitted in Excel > Preferences > Security.

Frequently Asked Questions

Why do my breakpoints disappear after I run the macro?

Breakpoints are not saved with the workbook. Resetting the project, closing the file, or recompiling clears them, so you must set them again each session.

Can I set a breakpoint on a blank line or a Dim statement?

No. VBA only pauses on executable statements. Put the breakpoint on the first line that actually does something.

Why does F8 step over my breakpoint?

Stepping runs code line by line and ignores breakpoints on lines it does not reach. If the procedure takes a different branch, the marked line is simply skipped.

Do breakpoints work in a password-protected VBA project?

Only after you unlock the project with the password. Without it, the code is hidden and cannot be edited or paused.

Why does my Worksheet_Change code never stop at the breakpoint?

Events are probably switched off. Type Application.EnableEvents = True in the Immediate Window and press Enter, then try again.

Is there a way to pause only when a value changes?

Yes. Use Debug > Add Watch on the variable and choose to break when the value changes, which is more precise than a fixed breakpoint.