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

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

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

In line 2, Excel uses the Offset property of the active cell. This property tells the cursor to move a certain number of cells up or down and a certain number of cells left or right.

The Offset property code tells Excel to move 15 rows down and 0 columns across from the active cell (in this case, A1). Excel doesn’t select a cell with a specific address as it did when recording an absolute reference macro.

Between Offset and Select on the second line is Range(“A1”). This is Excel recording that you only selected one cell — the first cell of the range that is offset from the active cell. It’s a quirk of the Macro Recorder and isn’t necessary when you select only one cell. (The Macro Recorder records a lot of unnecessary code.) If you had selected, say A16:B17 instead of just A16, it would have recorded:

ActiveCell.Offset(15, 0).Range("A1:B2").Select

To see this macro in action, delete the total row for both tables and do the following:

1 Select cell A1.

2 Click Macros on the Developer tab.

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