Finding Names

H

hughg

Please could anyone tell me why the following formula doesn't work? I
am trying to find out if a name already exists in my worksheet. What
ever name is entered through a message box it remains perminently
false.

Function IsNameInWorkbook(stName As String) As Boolean
Dim X As String
Dim Rng As Range

Application.Volatile
On Error Resume Next
Set Rng = Application.Caller
Err.Clear
If Rng Is Nothing Then
X = ActiveWorkbook.Names(stName).Name
Else
X = Rng.Parent.Parent.Names(stName).Name
End If
If Err.Number = 0 Then IsNameInWorkbook = True
End Function



Many thanks for any help
 
J

JE McGimpsey

hughg said:
Please could anyone tell me why the following formula doesn't work? I
am trying to find out if a name already exists in my worksheet. What
ever name is entered through a message box it remains perminently
false.

The User Defined Function works fine for me. It finds any workbook-level
names and any worksheet-level names on the active sheet (or if the sheet
is specified - e.g., Sheet2!MyName).

I'm not sure, though, what you mean by "name is entered through a
message box".

Names are typically "entered" via either the Name Box on the Formula
toolbar, or via Insert/Name/Define.
 
H

hughg

The User Defined Function works fine for me. It finds any workbook-level
names and any worksheet-level names on the active sheet (or if the sheet
is specified - e.g., Sheet2!MyName).

I'm not sure, though, what you mean by "name is entered through a
message box".

Names are typically "entered" via either the Name Box on the Formula
toolbar, or via Insert/Name/Define.

I'm trying to find text names that have been entered on a
database.....am I barking up the wrong tree?
 
B

Bob Greenblatt

I'm trying to find text names that have been entered on a
database.....am I barking up the wrong tree?
Sounds like it. If you are looking for a database field name, which is
usually at the top of a column, use edit-find. That should find the text you
are looking for.
 
H

hughg

Sounds like it. If you are looking for a database field name, which is
usually at the top of a column, use edit-find. That should find the text you
are looking for.

Thanks All

Cracked it, it was staring me in the face!
Selection.AutoFilter Field:=4,
Criteria1:=Application.InputBox(prompt:="Enter Name", Type:=2),
Operator:=xlOr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top