|
|
| Back to Excel Homepage | Excel VBA - Reference Guide |
|
Menu Looking at the code
Other links
|
VBA code is stored in a module which is part of the Excel workbook but is viewed via the Visual Basic Editor (VBE) interface.
1. Click the Macro icon from the Developer tab. 2. Select the macro you wish to view. 3. Click on the Edit button.
Now look at the differences between the absolute and the relative macros.
Absolute Macro
Range(“A1”).Select In plain English, this means, “click on the cell A1”. ActiveCell.FormulaR1C1 = “ABC Ltd” In plain English, this means “enter the text ABC Ltd into the active cell”.
Relative Macro
Activecell.Select In plain English, this means, “click on the active cell”. ActiveCell.FormulaR1C1 = “ABC Ltd” In plain English, this means “enter the text ABC Ltd into the active cell”. ActiveCell.Offset(1,0).Range(“A1”).Select In plain English, this means, “select the cell one row down, but stay in the same column”. OffSet (Keyword)Offset is a command used in relative macros, which allows you to select a particular cell in relation to the active cell.
Unnecessary CodeAs previously mentioned, recording macros does create a lot of unnecessary code. In this example, the Range("A1") that appears in rows 3, 5, 7, 9 and 11 of the relative macro is unnecessary and can be removed.
|
Tip: Alt + F11 function keys switches between Excel and VBE window.VBA Keywords: ActiveCell, Range, Selection, OffSet.Note: For further details and other members, see Range/Selection objects. |
|
© copyright 2010 TP Development & Consultancy Ltd, All Rights Reserved. All trademarks are copyrighted by their respective owners. Please read our terms of use and privacy policy. |