Excel VBA for Beginners: Record, Read, and Edit Your First Macro
VBA has been automating Excel since 1993, and it is still the fastest way to eliminate repetitive work in a workbook. The on-ramp is gentler than people think, because Excel writes the first draft for you: record a macro, then read and edit the code. Here is that path, step by step.
Setup: two one-time things
- Enable the Developer tab: File > Options > Customize Ribbon > check Developer.
- Know that macros need a .xlsm file. Saving as regular .xlsx silently strips your code — the classic beginner heartbreak.
Record something real
Developer > Record Macro. Name it (no spaces), then do a real chore: bold the header row, auto-fit columns, add a filter. Stop recording (button in the status bar). Press Alt + F8 to run it anywhere.
Now read what it wrote
Press Alt + F11 to open the VBA editor and find your macro in Module1:
Sub FormatReport()
Rows("1:1").Select
Selection.Font.Bold = True
Cells.EntireColumn.AutoFit
Range("A1").Select
Selection.AutoFilter
End Sub
Recorded code selects things and then acts on the selection, because that is literally what you did with the mouse. Code does not need the mouse. The same macro, cleaned up:
Sub FormatReport()
Rows(1).Font.Bold = True
Cells.EntireColumn.AutoFit
Range("A1").AutoFilter
End Sub
Shorter, faster, and it does not hijack the user’s cursor. "Delete the Selects" is the single most valuable VBA editing skill.
Add what the recorder cannot: logic
Recorders replay actions; they cannot decide anything. This loop flags every past-due row — something no recording can express:
Sub FlagOverdue()
Dim lastRow As Long, i As Long
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastRow
If Cells(i, 4).Value < Date Then
Rows(i).Interior.Color = RGB(255, 199, 206)
End If
Next i
End Sub
Three ideas cover most beginner VBA: find the last row with End(xlUp), loop with For, decide with If. Everything else is looking up which property to set — which the macro recorder will happily reveal: record the action once, read the property name, delete the recording.
Make it a button
Developer > Insert > Button (Form Control), draw it on the sheet, assign your macro. Now the whole cleanup is one click for anyone who opens the workbook.
Guardrails
- There is no undo for macros. Save before running anything that writes to cells.
- Test on a copy of real data, not the original.
- Ctrl + Break (or Esc) interrupts a runaway loop.
- When you open a workbook with macros, Excel shows a security banner — enable content only for files you wrote or trust.
VBA is worth learning even in the Power Query era: transformations belong in Power Query, but button-driven workflows, custom formatting passes, and workbook manipulation are still squarely VBA territory.