XL5: Name Defined Incorrectly If Sheet Name Contains Space

Last reviewed: September 2, 1997
Article 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: 5.00
Keywords : kbprg SynFnc kbcode kbprg
Version : 5.00
Platform : WINDOWS


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: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.