Breakpoints, Watches & Immediate Window: Advanced Debugging in VBA
Master the VBE’s tools to see what your code is doing—live.
Breakpoints (F9)
Stop execution at a line to inspect state. Conditional breakpoints: right-click breakpoint → Condition.
Watches
Track variable expressions while stepping.
- Debug → Add Watch
- Enter expression (e.g.,
lastRoworCells(r, "C").Value) - Choose Break When Value Is True to pause automatically
Immediate Window (Ctrl+G)
Evaluate expressions and call procedures at runtime.
? Worksheets("Data").Range("A1").Value Call TestProcedure(42)
Practical example
Sub Analyze() Dim lastRow As Long, r As Long lastRow = Cells(Rows.Count, "A").End(xlUp).Row For r = 2; r <= lastRow; r = r + 1 Debug.Print r, Cells(r, "A").Value Next r End Sub
Set a Watch on lastRow, a Breakpoint inside the loop, and print diagnostic output in Immediate.
Work faster with the VBA Assistant
Create, explain, and improve your VBA code with examples, comments, and best practices—directly in your workflow.
