Читать книгу Excel Macros For Dummies онлайн
29 страница из 60
6 Click OK to start recording.
7 Select cell A16 and type Total in the cell.
8 Select the first empty cell in Column D (D16) and type = COUNTA(D2:D15).
9 Click Stop Recording on the Developer tab to stop recording the macro.
ssss1 Recording a macro with relative references.
At this point, you have recorded two macros. Take a moment to examine the code for your newly created macro.
Click Macros from the Developer tab to open the Macro dialog box. Here, choose the AddTotalRelative macro and click Edit.
Again, this opens the Visual Basic Editor to show you the code that was written when you recorded your macro. This time, your code looks something like the following:
Sub AddTotalRelative() ActiveCell.Offset(15, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "Total" ActiveCell.Offset(0, 3).Range("A1").Select ActiveCell.FormulaR1C1 = "=COUNTA(R[-14]C:R[-1]C)" End Sub
Notice that there are no references to any specific cell ranges at all. Take a look at what the relevant parts of this VBA code really mean.