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

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

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

To see your macro in action, delete the total row you just added and play back your macro by following these steps:

1 Click Macros on the Developer tab.

2 Find and select the AddTotal macro you just recorded.

3 Click the Run button.

If all goes well, the macro plays back your actions to a T and gives your table a total. Now here’s the thing: No matter how hard you try, you can’t make the AddTotal macro work on the second table (G1:I15 in Figure 1-3). Why? Because you recorded the macro using absolute references.

To understand what this means, examine the underlying code. To examine the code, click Macros on the Developer tab to open the Macro dialog box, as shown in Figure 1-4.


ssss1 Your post-totaled worksheet.


ssss1 The Excel Macro dialog box.

Select the AddTotal macro and click the Edit button. This opens the Visual Basic Editor to show you the code that was written when you recorded your macro:

Sub AddTotal() Range("A16").Select ActiveCell.FormulaR1C1 = "Total" Range("D16").Select ActiveCell.FormulaR1C1 = "=COUNTA(R[-14]C:R[-1]C)" End Sub

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