In Excel VBA, Step Into runs a macro one statement at a time and enters any procedure or function the current line calls. Open the macro in the Visual Basic Editor, place the cursor inside it, and press F8 on Windows; the yellow highlight shows the next statement that will run.
What Step Into Does
Step Into is a debugging command, not a way to edit a macro or move through a worksheet cell by cell. It pauses VBA between executable statements so you can observe the order in which the code runs. Each time you invoke the command, VBA performs the highlighted statement and pauses again at the next point in the execution path.
The important distinction is that Step Into follows calls to other procedures. If the highlighted line calls a Function or Sub, the next step takes you into that procedure’s code, where you can inspect its own statements. This is useful when you suspect the problem is inside a helper routine, but it can also mean stepping through more code than you need.
While execution is paused, the yellow highlight marks the next statement, and a yellow arrow in the editor’s margin indicates the current position. Variables may be inspected in the Locals window, with the mouse over a variable, or in the Immediate window. The value shown is the value at that point in the macro, not necessarily its final value.
How to Start Stepping Through a Macro
In Excel for Microsoft 365 on Windows, use this sequence:
- Save a copy of the workbook before running the macro. VBA changes cannot be reversed with Ctrl+Z.
- Open the workbook in the Excel desktop app. Press Alt+F11 to open the Visual Basic Editor (VBE). If the Developer tab is not visible, enable it through File > Options > Customize Ribbon and select Developer.
- In the VBE Project Explorer, find the workbook and open the module containing the macro. You can also click a macro in Excel and choose Edit if that option is available.
- Click inside the procedure you want to debug. Choose Debug > Step Into in the VBE, or press F8. If the macro has not started, VBA begins it and pauses at its first executable statement.
- Press F8 repeatedly to execute the highlighted statement and advance. Watch the code position and variable values, and use Run > Reset or the Reset button when you need to stop the paused macro.
F8 is a Visual Basic Editor shortcut; it is not the same as pressing a worksheet key while the Excel window has focus. If the editor does not respond, click its code window first. Some keyboards assign media or hardware controls to function keys, so you may need to hold Fn while pressing F8. The VBE’s Debug menu provides the command without relying on the function key.
A Small Example of Step Into
This example adds two amounts by calling a separate function. It illustrates why Step Into is useful: the addition is performed in a different procedure from the main macro.
Sub ShowTotal()
Dim firstAmount As Double
Dim secondAmount As Double
Dim combined As Double
firstAmount = 12.5
secondAmount = 3
combined = AddAmounts(firstAmount, secondAmount)
MsgBox CStr(combined)
End Sub
Private Function AddAmounts(ByVal firstAmount As Double, ByVal secondAmount As Double) As Double
AddAmounts = firstAmount + secondAmount
End Function
To follow the example, place the cursor inside ShowTotal and press F8. As you advance through the assignments, the variables receive 12.5 and 3. When execution reaches the call to AddAmounts, Step Into takes you into that function. The function adds the arguments and returns 15.5; the macro then displays 15.5 in a message box. This arithmetic is simply 12.5 + 3 = 15.5.
To inspect the values, open the Locals window through View > Locals Window in the VBE. The Immediate window is available through View > Immediate Window; while paused, you can enter an expression such as ? combined and press Enter to ask VBA to print its current value there. The Immediate window can also execute commands, so avoid entering anything that changes data unless that is intentional.
Step Into Versus Step Over and Step Out
VBA offers other stepping commands for different levels of detail. The best choice depends on whether you need to inspect a called routine or just let it run:
- Step Into (F8): Runs one statement and enters a called Sub or Function. Use it to examine the internal logic of a routine.
- Step Over (Shift+F8): Runs the current statement without stepping through a called routine. If the statement calls a function, VBA executes that function and pauses at the next statement in the current procedure.
- Step Out (Ctrl+Shift+F8): Finishes the current procedure and pauses back in the procedure that called it, if there is one. It is useful when you have gone inside a routine and no longer need to inspect its remaining lines.
For example, if the function in the sample is trusted and you only want to see whether the result is assigned correctly, Step Over skips its internal line and returns to the main macro. If the returned number is wrong, Step Into lets you inspect the calculation. Step Out is not the same as stopping the entire macro: it completes the current procedure before returning to its caller.
Breakpoints and Other Ways to Pause
You do not have to start at the first line and press F8 through every statement. A breakpoint tells VBA to run normally until it reaches a chosen line, then pause. Click in the left margin beside an executable line and press F9, or use Debug > Toggle Breakpoint. The line is marked, commonly with a red indicator. Run the macro, then use F8 to continue slowly from the pause.
Breakpoints are handy when the issue occurs late in a long procedure, or when a loop repeats many times. You can remove a breakpoint by toggling it again, or clear breakpoints through the VBE’s Debug menu. A breakpoint does not change the macro’s logic; it changes where the editor pauses during debugging. You can also use Debug > Add Watch to monitor an expression or variable while code runs, which helps identify when its value changes.
How to Read the Paused State
Step Into only makes sense when you distinguish the statement just completed from the one about to run. The yellow highlight is the next line of executable code. If you pause before an assignment, the destination variable may still hold its earlier value. Step once, then inspect the variable again to see the effect.
Code may also branch. An If statement can cause VBA to skip a block, and a loop can return execution to an earlier line. A skipped line is not necessarily a failure: the condition may have directed VBA elsewhere. To understand the route, inspect the condition and its variables at the pause point. A watch or the Locals window can be more informative than trying to infer values from the worksheet after the macro finishes.
Common Problems and Safe Debugging
- F8 does nothing: Confirm that the VBE code window has focus and that execution is not already paused elsewhere. Try Debug > Step Into or use Fn+F8 on a keyboard that uses function keys for other controls.
- VBA reports a compile error: The editor may stop before the macro can run, for example if a name is misspelled or a required procedure is missing. Correct the error first. Choose Debug > Compile VBAProject if available to check the project for compile problems.
- The macro changes a worksheet while stepping: Stepping is not a preview or a transaction. Statements that write values, delete sheets, or save files can take effect as they run. Save a separate copy and, where practical, test on sample data.
- The code jumps into unexpected code: A called procedure may be in another module, a worksheet module, or the workbook module. Follow the editor’s highlighted position and check the Project Explorer to identify the module.
To stop execution, use the VBE Reset command or button. Reset ends the running procedure and clears its current execution state; it does not restore workbook data changed before the reset. Ctrl+Z cannot undo most VBA actions. Also be cautious when opening a workbook containing macros: run code only when you trust its source and understand its purpose. Do not enable macros merely to inspect an unfamiliar file.
Windows, Mac, and Excel for the Web
These steps target desktop Excel for Microsoft 365 on Windows. Excel for Mac also includes the Visual Basic Editor and VBA debugging commands, but keyboard behavior can differ by keyboard and macOS settings. Use the VBE’s Debug > Step Into menu command if F8 is intercepted; on some Mac keyboards, holding Fn with the function key is needed. The shortcut for opening the editor can also vary with the keyboard, so use Excel’s menu or keyboard-shortcut settings when necessary.
Excel for the web does not run or provide the full VBA editor for desktop macros. To debug a VBA macro, open the workbook in the desktop version of Excel. Keep a macro-enabled format such as .xlsm if you need to preserve VBA; saving a macro-containing workbook as .xlsx removes its VBA project.
Frequently Asked Questions
What does Step Into mean in an Excel macro?
It executes one VBA statement at a time and enters any Sub or Function called by that statement, allowing you to inspect the code and its values as it runs.
What is the shortcut for Step Into in Excel VBA?
In the Visual Basic Editor on Windows, press F8. If the key is assigned to a hardware function, try Fn+F8 or select Debug > Step Into from the VBE menu.
What is the difference between Step Into and Step Over?
Step Into enters a procedure called on the current line. Step Over lets that procedure run and pauses at the next statement in the current procedure.
Can I use Step Into in Excel for the web?
No. Excel for the web does not provide the desktop VBA editor or run VBA macros. Open the workbook in desktop Excel to debug its macro.
Can I undo a macro after stepping through it?
Usually not with Ctrl+Z. VBA actions generally do not create Excel’s normal undo history, so save a backup and test on a copy before stepping through code that changes data.
Related
- Compare Two Columns of Names in Excel: Find Matches
- Excel Table Styles: How to Apply and Customize Them
- Cut, Copy, and Paste in Excel: Shortcuts and Steps
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Create a Pivot Table in Excel Using VBATo create a PivotTable with VBA, prepare a rectangular data range with clear headers, then use a PivotCache…
- Outlook Macros: How to Enable Them Safely in Classic OutlookTo enable VBA macros in classic Outlook for Windows, open File > Options > Trust Center > Trust…
- Excel VBA UserForm Data Entry: Build a Simple FormTo enter data through an Excel VBA UserForm, create a form with text boxes and a Save button,…
- Input Box in Excel VBA: Use InputBox and Get DataIn Excel VBA, use InputBox to ask for a text value, or Application.InputBox when you want to restrict…
- Excel SUBSTITUTE in VBA: Replace or WorksheetFunctionTo substitute text in Excel VBA, use VBA’s built-in Replace function; it replaces every matching occurrence by default.…
- VBA Array Add: How to Append Values and Resize an ArrayVBA has no built-in Array.Add method. To add values, use a dynamic array and resize it with ReDim…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.