Excel

Page 100

Chapter 6: Using the Excel Macro Recorder 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 ‘ 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.

Recording in relative mode In some cases you want your recorded macro to work with cell locations in a relative manner. You may want the macro to start entering the month names in the active cell. In such a case, you need to use relative recording. You can change the manner in which Excel records your actions by clicking the Use Relative References button on the Code group on the Developer tab. This button is a toggle button. When the button appears in a pressed state, the recording mode is relative. When the button appears normally, you are recording in absolute mode. You can change the recording method at any time, even in the middle of recording.

83


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.