![]() ![]() Don’t worry it is the byproduct behavior of macro recording.I need to use the Excel Solver several times in a worksheet. Notice that the code refers to cell A1 even we never used cell A1 during the macro recording. The day names are always entered beginning at the active cell. To test, activate any cell and then execute the Relative macro. This macro always starts entering text in the active cell. ![]() With the recording mode set to relative, the code that Excel generates is quite different from the code generated in absolute mode: Sub Relative()ĪctiveCell.Offset(1, 0).Range("A1").SelectĪctiveCell.Offset(-2, 0).Range("A1").Select Click cell C1 to activate it again and stop the macro recording.Click Record Macro button, type Relative as the name for this macro and click OK to begin recording.Make sure that the Use Relative References button is highlighted:Īs we don’t need to record 1st cell selection so we must activate the beginning cell ( C1) before start the macro recording. To see how relative mode recording works, delete the contents of range A1:A3 and then perform the following steps:Ĭlick the Use Relative References button to change the recording mode to relative from the Developer tab. In such a case, we need to use relative recording. For example, we want the macro to start entering the day names in the current active cell. Sometimes we want our recorded macro to work with cell locations in a relative references mode. In this case, the macro always enters the names of the first three days in the range A1:A3 on the active worksheet. A macro recorded by using absolute references always produces the same results on same range when it’s executed. These same actions occur regardless of which cell is active when you execute the macro. When executed, this macro selects cell A1 and inserts the Monday, Tuesday and Wednesday into the range A1:A3. Press Alt+F11 to activate the VBE to examine the Module1 module:Įxcel generates the following code: Sub AbsoluteMacro() ![]() Click cell A1 to activate it again and stop the macro recording.Click Record Macro button, type Absolute as the name for this macro and click OK to begin recording.This macro simply enters the Monday, Tuesday and Wednesday in a worksheet. Before start recording macro, make sure that the Use Relative References button is not highlighted. Open a new workbook and follow these steps to record a simple macro in absolute mode. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |