Главная » Excel Macros For Dummies читать онлайн | страница 28

Читать книгу Excel Macros For Dummies онлайн

28 страница из 60

Pay particular attention to lines 2 and 4 of the macro. When you asked Excel to select cell range A16 and then D16, those cells are exactly what it selected. Because the macro was recorded in absolute reference mode, Excel interpreted your range selection as absolute. In other words, if you select cell A16, that cell is what Excel gives you. In the next section, you take a look at what the same macro looks like when recorded in relative reference mode.

Recording macros with relative references

In the context of Excel macros, relative means relative to the currently active cell. So you should use caution with your active cell choice — both when you record the relative reference macro and when you run it.

First, make sure the Chapter 1 Sample File.xlsx file is open. Then, use the following steps to record a relative-reference macro:

Figure1-5

2 Before recording, make sure cell A1 is selected.

3 Click Record Macro from the Developer tab.

4 Name the macro AddTotalRelative.

5 Choose This Workbook in the Macros In drop-down list.

Правообладателям