Recording in absolute mode

Follow these steps to record a simple macro in absolute mode. This macro simply enters three month names into a worksheet:

1. Choose ToolsOMacroO Record New Macro.

2. Type Absolute as the name for this macro.

3. Click OK to begin recording.

4. Activate cell B1 and type Jan in that cell.

5. Move to cell C1 and type Feb.

6. Move to cell D1 and type Mar.

7. Click cell B1 to activate it again.

8. Stop the macro recorder.

9. Press Alt+F11 to activate the VBE. 10. Examine the Module1 module.

Excel generates the following code:

Sub Absolute()

' Absolute Macro

' Macro recorded by John Walkenbach


ActiveCell.FormulaR1C1 =

= "Jan"


ActiveCell.FormulaR1C1 =

= "Feb"


ActiveCell.FormulaR1C1 =

= "Mar"


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 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.


0 0

Post a comment