Excel: Benefits of Using Defined Names in Macros

Last reviewed: November 2, 1994
Article ID: Q51300

SUMMARY

Assigning names to variables provides two important benefits when writing macros in Microsoft Excel:

  1. Names improve the readability of the macro.

  2. Names help avoid problems caused by rearrangement of the worksheet.

Macros that use names are more easily understood than those that use only formulas or data. For example, the formula "SUM(assets)" is much more informative about the cell contents than "SUM(C14:C28)".

When a worksheet is altered so that cell positions are changed, such as when a column or row is added, external references to the sheet using names continue to reference the appropriate cells. The use of cell references in such cases can result in incorrect operation.

The use of names does not slow down macro operations; however, there is a performance penalty when names are first defined.

Names can be defined by using any of the following commands:

   DEFINE.NAME()
   SET.NAME()
   ARGUMENT()
   FOR()

Set names in quotation marks only when defining a name or when the name text rather than the current value of the name is of interest. This applies to the following macro commands:

   SET.NAME()
   DEFINE.NAME()
   FOR()
   DELETE.NAME()
   ARGUMENT()
   GET.NAME()

MORE INFORMATION

More information on macro functions is available in the "Microsoft Excel Function Reference" version 3.00 manual.


KBCategory: kbother
KBSubcategory:

Additional reference words: 1.00 1.03 1.04 1.06 1.50 2.20 3.00


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.