Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can i check if a named range exists with VBA?

403 views
Skip to first unread message

Janis Speks

unread,
Nov 13, 1997, 3:00:00 AM11/13/97
to

Hello world

How can i check if a named range exists
with VBA?
Using: Excel97
--
Thanks in advance

Janis Speks
BeslutsData AB
Stockholm, Sweden

John Green

unread,
Nov 14, 1997, 3:00:00 AM11/14/97
to

In article <01bcf02d$685c3840$6d4907c3@janis> on Thu, 13 Nov 1997
04:10:45 -0800 "Janis Speks" <janis...@beslutsdata.se> wrote:
<< How can i check if a named range exists
with VBA? >>

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


0 new messages