Recording Absolute Macro
Follow these steps to record a simple macro in absolute mode. This macro simply enters three month names into a worksheet:
- Choose Developer> Code> Record Macro.
- Type Absolute as the name for this macro.
- Click OK to begin recording.
- Activate cell B1 and type Jan in that cell.
- Move to cell C1 and type Feb.
- Move to cell D1 and type Mar.
- Click cell B1 to activate it again.
- Stop the macro recorder.
- Press Alt+F11 to activate the VBE.
- Examine the Module1 module.
Excel generates the following code:
Sub Absolute() ' ' Absolute Macro ' Macro recorded by Rodi Ken ' Range("B1").Select ActiveCell.FormulaR1C1 = "Jan" Range("C1").Select ActiveCell.FormulaR1C1 = "Feb" Range("D1").Select ActiveCell.FormulaR1C1 = "Mar" Range("B1").Select End Sub
When executed, this macro selects cell B1 and inserts the three month names in the range B1:D1. Then the macro reactivates cell B1.
These same actions occur regardless of which cell is active when you execute the macro. A macro recorded by using absolute references always produces the same results when it is executed. In this case, the macro always enters the names of the first three months into the range B1:D1.