Page 187 - Excel Data Analysis
P. 187

10 537547 Ch09.qxd  3/4/03  12:13 PM  Page 173






                                                                  AUTOMATING ACTIONS WITH MACROS 9




                                           When you view the VBA code for your macro, you may notice that a single
                                           quote (') precedes several lines. These lines are called comment lines;
                                           programmers use these lines to provide information about the code, such as
                                           what the code does, when it was created, or even who coded it. When you use
                                           the Macro Recorder to create a macro, by default Excel adds several comment
                                           lines. These comment lines always indicate the name of the macro, the creation
                                           date, and the programmer. If the programmer created a keyboard shortcut for
                                           the macro, the comments contain this information as well. Making modifications
                                           to the comment lines does not affect the macro execution. In fact, Excel ignores
                                           any line of text or code preceded by a single quote when the macro executes.

                                           Example:
                                           Private Sub add()
                                           '
                                           ' add Macro
                                           ' Macro recorded 5/19/2001 by Jinjer Simon
                                           '
                                           ' Keyboard Shortcut: Ctrl+d
                                           '
                                              ActiveCell.FormulaR1C1 = "=SUM(RC[-6]:RC[-1])"

                                           End Sub









                                                                                  Format_Currency
                                                                                  Format_Currency
















                     Á Click the module that   Note: You may need to insert a blank   ‚ In the Macro dialog box,   ± Close the Macro dialog
                     contains the code for the   line.                  click the macro from which   box.
                     macro you want to update.                          you copied source code.
                                              ° Click the Paste button.                           ■ When you run the updated
                     ‡ Place the cursor between                         — Click Delete to remove   macro, Excel executes the
                     the last line of code and the   · Close the Visual Basic   the macro.        original and copied code.
                     End Sub command.         Editor.

                                                                                                                     173
   182   183   184   185   186   187   188   189   190   191   192