The information in this article applies to:
SYMPTOMSIn Microsoft Excel, you may receive one or more of the following error messages when you use the Range(Name).Value method in Microsoft Visual Basic for Applications to get a value based on a defined name. -and-
CAUSEThis problem occurs if the defined name in question refers to a constant value or a formula rather than a range. RESOLUTIONTo prevent the error message from appearing, use the Evaluate method to determine the value of the defined name. Please see the "More Information" section of this article for an example that demonstrates this issue. MORE INFORMATION
If a particular defined name refers to a constant value or a formula,
you can use the .Evaluate(Name) method to get the value of the name. The .Evaluate(Name) method can evaluate formulas and constant values even if they don't refer to an actual range.
and you use the Range(Name).Value and .Evaluate(Name) methods to get the values of the names, you receive the following results in your macro:
NOTE: Error messages 1 and 2 are as follows:
Sample Visual Basic ProcedureMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.asp Check the Value of a NameTo check the value of a name, you can use the following subroutine:
To check the value by using .Evaluate(Name), use
in place of the previous test line.
MsgBox TestIn order to prevent an error when the name refers to an error value (in this case, if the name is Golf), use the Names(Name).RefersTo method to check the name before getting its value. For example, you could use:
If the name refers to an error value, the IsError test is true and the error message box is displayed. Otherwise, the OK message box is
displayed. For example, if the name is Golf, which refers to =#N/A, the
error message box is displayed. Using any of the other example names
results in the OK message box.
REFERENCESFor more information about the Evaluate method, in the Visual Basic Editor, click
Microsoft Visual Basic Help on the Help menu, type
Evaluate Method in the Office Assistant or the Answer Wizard, and
then click Search to view the topic. Q231955 OFF: Office Assistant Not Answering Visual Basic QuestionsFor additional information about getting help with Visual Basic for Applications, please click the article number below to view the article in the Microsoft Knowledge Base: Q226118 VBA: Programming Resources for Visual Basic for Applications Additional query words: XL2000
Keywords : kbprg kbdta kbdtacode OffVBA PgmOthr KbVBA |
Last Reviewed: September 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |