Article ID: 108517
Article Last Modified on 10/11/2006
This
Name Refers to Cell information
---------------------------------------------------------------
Alpha =Sheet1!$B$1 Cell B1 contains the number 1
Bravo =2
Charlie =SUM(Sheet1!$B$3:$C$3) Cell B3 contains the number 3
Cell C3 contains the number 4
Delta =Alpha
Echo =Charlie
Foxtrot =Alpha+Charlie
Golf =#N/A
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:
Name Range(Name).Value Sheets("Sheet1").Evaluate(Name)
--------------------------------------------------------------
Alpha 1 1
Bravo [Error message 1] 2
Charlie [Error message 1] 7
Delta 1 1
Echo [Error message 1] 7
Foxtrot [Error message 1] 8
Golf [Error message 1] [Error message 2]
NOTE: Error messages 1 and 2 are as follows:
'----------------------------------------------------------------------
Option Explicit
Sub CheckNameValue()
Dim Test As Variant
Test = Range("Alpha").Value
'To check the value by using .Evaluate(Name), use
'
' Test = Sheets("Sheet1").Evaluate("Alpha")
'
'in place of the previous test line.
MsgBox Test
End Sub
'----------------------------------------------------------------------
In 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:
Sub CheckForError()
'If the name Golf refers to an error value, such as #REF! or #N/A,
If IsError(Evaluate(Names("Golf").RefersTo)) Then
'then show an error message to that effect,
MsgBox "Golf is an error name!"
Else
'otherwise state that the name refers to a good reference.
MsgBox "Golf is OK!"
End If
End Sub
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.
176476 OFF: Office Assistant Not Answering Visual Basic Questions
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: vba
Keywords: kbdtacode kbprb kbprogramming KB108517