By default, Excel records macros in absolute mode. In absolute mode, a macro will start working in the same cell it was in when it was recorded. If A1 was the active cell during recording, the macro will return to A1 and begin working from there no matter which cell was selected prior to starting the macro.
When you turn on relative reference before recording a macro, it will start the macro "relative" to whatever cell is currently selected. Instead of recording fixed cell addresses, Excel captures each action as an offset from the active cell. This makes the macro reusable across different locations in your worksheet and far more flexible for everyday tasks.
Understanding the difference between absolute and relative reference in an Excel macro is essential for building macros that work reliably no matter where you need them.
| Feature | Absolute Reference | Relative Reference |
|---|---|---|
| Default behavior | On by default when recording | Must be toggled on before recording |
| Starting cell | Always returns to the exact cell used during recording | Starts from whatever cell is currently selected |
| VBA code output | Uses fixed addresses like Range("A1") | Uses ActiveCell.Offset(row, column) |
| Best use case | Tasks that must always target a specific cell or range | Tasks you need to repeat in different locations across a worksheet |
In this example, you start recording a macro in Cell A6 and record the action of inserting a row. Here is how the result differs depending on whether you use absolute or relative reference.
**1. With Absolute Reference**
With absolute reference, no matter which cell is selected when you run the macro, it will always insert a row at Row 6, because the macro recorded the exact cell address.
**2. VBA Code in Edit Mode (Absolute)**
The VBA code below shows how Excel recorded the action using a fixed cell reference.
**3. With Relative Reference**
With relative reference, the macro inserts a row relative to whichever cell is currently selected. For example, if Cell A9 is selected, the macro will insert a row at Row 9.
**4. VBA Code in Edit Mode (Relative)**
The VBA code below shows how Excel recorded the same action using an offset from the active cell instead of a fixed address.
**5. How to Toggle Relative Reference**
Click the Use Relative References button in the Code group on the Developer tab to toggle relative reference on and off. When the button appears highlighted, relative reference mode is active.
If your relative reference macro is not behaving as expected, check for these common issues:
Mastering macros and relative references is just one step toward getting more out of Excel. Pryor Learning offers live seminars and on-demand courses that cover everything from foundational spreadsheet skills to advanced VBA programming. Explore Pryor's Excel training options to take your productivity to the next level.