Tutorial 7 Understanding Absolute and Relative Recording in a Spreadsheet Macro

Tutorial 7 Understanding Absolute and Relative Recording in a Spreadsheet Macro

<p> Tutorial 7: Using relative referencing in a spreadsheet macro</p><p>This tutorial takes you through the creation of an Excel macro that uses relative references. We’re going to create the MyTitle macro that you created in an earlier tutorial, but this time we’ll use relative references.</p><p>It’s a good idea to make sure you can easily do the steps in the macro again, before you actually start recording.</p><p>Repeat the recording of the MyTitle macro using relative cell addresses: 1 Select the cell A1. 2 From the Tools menu, select Macro/Record New Macro. 3 Type MyTitle2 in the Macro name box. 4 Type Enters a title into the cell 2 down and 2 right from the selected cell and formats the column in the Description box. 5 Press OK</p><p>The macro is now recording, and you should see the Stop Macro button on the screen on its own toolbar. 6 Press the Relative Reference button on the Stop Recording toolbar. 7 Turn off gridlines as follows: From the Tools menu select Options then select the View Tab. From the Windows options clear the Gridlines box and press OK. 8 Enter your name and format it as follows:  Select cell C3 (Note this is 2 down and 2 right from A1) enter YOUR FULL NAME, then press the Enter key.  Reselect the cell C3 and from the Format menu select Cells then select the Font tab.  Select a different Font and change the style to Bold, size to 18.  Press OK 9 Customize the column width as follows: From the Format menu, select Column and AutoFit Selection. 10 Click the Stop Recording button or from the Tools menu and select Macro/Stop Recording. 11 Test out the macro as before, but select a different starting Cell each time.</p><p>1 2005</p><p>Feedback</p><p>You should find that your name is printed in many cells. Each cell is located 2 down and 2 to the right of the cell that was selected when the macro was activated. </p><p>The advantage of using the relative cell reference is that you can operate on different groups of cells by selecting a different starting point. This makes you macro much more flexible.</p><p>Compare the relative code, shown below, with the previous version of the MyTitle macro that you created in an earlier tutorial.</p><p>MyTitle2 macro using relative cell references</p><p>Note that the only differences are in the early part with ActiveCell.Offset(2,2) etc. The (2,2) is our 2 down and 2 right location.</p><p>It is important to think about the finishing location of the macro. Macros are often used in combinations with other editing and bringing the selection back to the starting point or a point relative to the starting point is also important. The second last line in the code above returns the selection to the original cell 2 up and 2 left (-2, -2).</p><p>2 2005</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us