PDA

View Full Version : Solved: Return true or false if defined name is there?



Edoloto
10-23-2008, 06:24 AM
Greetings!

How can I check if my spreadsheet has a defined name. For example, I want to go to the spreadsheet (this I got it), then I want to check if there is a defined name (Range) called "Charge", if there is, then return true .. otherwise false. Then, go to the next spreadsheet.

I would greatly appreciate some ideas ...

Thanks,


Eduardo :help

CCkfm2000
10-23-2008, 07:28 AM
check this kb

http://www.vbaexpress.com/kb/getarticle.php?kb_id=729

p45cal
10-23-2008, 07:54 AM
Write a small function such as:Function NameExists(myName) As Boolean
For Each nm In ActiveWorkbook.Names
If UCase(nm.Name) = UCase(myName) Then NameExists = True
Next nm
End FunctionorFunction NameExists2(myName) As Boolean
On Error Resume Next
Set xx = ActiveWorkbook.Names(myName)
On Error GoTo 0
If Not IsEmpty(xx) Then NameExists2 = True
End Function
which you can use like this:MsgBox NameExists("Charge")or like this for the second one:MsgBox NameExists2("Charge"). remembering it works on the active workbook, and that this include all Names in the workbook, regardless of scope and regardless of whether the name represents a range or not.
Another example:If NameExists("Charge") Then...