fx Macro Recorder & VBA Basics

VBA Editor tour: modules, Immediate window, breakpoints

⏱ 13 min

What you'll learn

  • Open the editor
  • The main windows
  • Where code lives

Concept

1. Open the editor

Alt + F11 (Mac: Fn + Option + F11, or Developer → Visual Basic).

2. The main windows

Window Shortcut What it shows
Project Explorer Ctrl + R every open workbook and its sheets, modules
Properties F4 properties of the selected object (e.g. sheet code name)
Code window F7 the code
Immediate window Ctrl + G type and run single lines
Locals window View menu all variables and their current values while debugging

3. Where code lives

In Project Explorer, under your workbook:

  • Modules (Module1, Module2…) — normal macros go here. Insert → Module.
  • Sheet objects (Sheet1…) — code that reacts to events on that sheet, like Worksheet_Change.
  • ThisWorkbook — events of the whole file, like Workbook_Open.

Rename a module in the Properties window (e.g. modReports) to keep things organised.

4. Anatomy of a macro

Sub SayHello()
    ' A comment starts with an apostrophe
    MsgBox "Hello from ExcelWalaa!"
End Sub

Click inside it and press F5 to run.

5. Immediate window — your scratch pad

Press Ctrl + G. A ? prints a result:

? Range("A1").Value
? ActiveSheet.Name
? 18000 * 1.18

Without ?, it runs a command:

Range("A1").Value = "Test"
Sheets("Data").Select

In code, Debug.Print writes to this window — great for checking values without MsgBox pop-ups:

Debug.Print "Last row is "; lastRow

6. Debugging tools

Action Key Use
Run F5 run the macro
Step Into F8 run one line at a time; the yellow line is the next one to run
Breakpoint F9 (or click the grey margin) code pauses at this line (red dot)
Reset Stop button stop a paused macro
Hover mouse over a variable shows its current value

A typical flow: put a breakpoint on a suspicious line → F5 → code stops there → hover over variables or check the Locals window → F8 to go line by line.

7. When an error appears

A runtime error dialog offers Debug — click it and the problem line turns yellow. Fix the line, then press F5 to continue or Reset to stop.

8. Comment a block quickly

View → Toolbars → Edit → use the Comment Block / Uncomment Block buttons.

Common mistakes

Writing normal macros inside a sheet module (they still work but get lost). Forgetting a macro is paused in break mode (Excel feels "frozen"). Pressing F5 when the cursor isn't inside a Sub.

Exercises

mediumOpen the macro you recorded in Lesson 1. Add a Debug.Print "Done" line at the end, set a breakpoint on the first line, and step through it with F8 while watching the sheet change. In the Immediate window, find the name of the active sheet and the value of B2.
Set the breakpoint with F9, step with F8, and add Debug.Print "Done" before End Sub. In Immediate use ? ActiveSheet.Name and ? ActiveSheet.Range("B2").Value. The output should match the visible sheet name and B2; Done appears once after the final step.

Quiz

Shortcut for the Immediate window?
Ctrl + G
Key to run one line at a time?
F8
Where should normal macros be written?
In a standard module
VBA Editor tour: modules, Immediate window, breakpoints · Automation | ExcelWalaa