XL5: Name Defined Incorrectly If Sheet Name Contains Space

ID: Q117125


The information in this article applies to:
  • Microsoft Excel for Windows, version 5.0


SYMPTOMS

In Microsoft Excel version 5.0, if you use a Visual Basic, Applications Edition, subroutine to define a name on a worksheet and the name of the worksheet contains a space, the name is not defined correctly.


CAUSE

This problem may occur if you use the following syntax to define a name:


   Workbooks(BookName).Sheets(SheetName).Range(RangeName).Name =
      "NameToDefine" 
If you use this syntax to define a name, the name may be incorrectly defined if the worksheet name contains a space. For example, if the worksheet name is "Sales Summary" and the range to refer to is $A$1, the name may be defined as

   =Sales SUMMARY!$A$1 
This defined name refers instead to the intersection of the ranges 'Sales' and 'SUMMARY!$A$1' instead of cell $A$1 on 'Sales Summary'.


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem was corrected in Microsoft Excel for Windows version 5.0c.


WORKAROUND

To avoid this problem, use the Names.Add syntax to define names in a Visual Basic subroutine, as in the following example:


   Workbooks(BookName).Names.Add Name:="NameToDefine",
      RefersTo:="='" & Sheets(SheetName).Name & "'!" &
      Sheets(SheetName).Range(RangeName).Address 
Note the use of apostrophes (') in the RefersTo argument. These apostrophes are included to ensure that the worksheet name is treated as a single name, instead of as two words separated by a space.

Using the above example, the name would be defined as

   ='Sales Summary'!$A$1 
This is the correct definition of the name.

Additional query words:

Keywords : kbprg
Version : WINDOWS:5.0
Platform : WINDOWS
Issue type :


Last Reviewed: October 25, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.