How can i check if a named range exists
with VBA?
Using: Excel97
--
Thanks in advance
Janis Speks
BeslutsData AB
Stockholm, Sweden
Hi Janis,
The following VBA function can be used in a worksheet cell to test for
a name in the workbook containing the cell, or can be called from
another VBA procedure to see if the name exists in the active workbook.
It returns True if the name exists and False if not.
Function NameInWorkbook(TestName As String) As Boolean
Dim x As String
On Error Resume Next
If IsError(Application.Caller) Then
x = ActiveWorkbook.Names(TestName).Name
Else
x = Application.Caller.Parent.Parent.Names(TestName).Name
End If
If Err = 0 Then NameInWorkbook = True
End Function
Sub TestName()
If NameInWorkbook(InputBox("What Name", vbQuestion)) Then
MsgBox "Name exists"
Else
MsgBox "Name does not exist"
End If
End Sub
John Green
Sydney
Australia
Microsoft MVP - Excel