ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check to see if a range name exists on a sheet (https://www.excelbanter.com/excel-programming/399228-check-see-if-range-name-exists-sheet.html)

Sajit

Check to see if a range name exists on a sheet
 
I have the following expression in a line of code that I am writing. The
fld_name(colm) is an array of names that may be on a given sheet. The
statement results in an application defined error, since the fld_name(2) does
not exist. How do I check for the existence of a name?

I did search the general question and the programming groups, did not find a
close enough answer.

a1 = ActiveWorkbook.Names(fld_name(colm)).RefersTo
--
Sajit
Abu Dhabi

Sajit

Check to see if a range name exists on a sheet
 
Thanks Dave, I suppose there isn't a direct function that would tell this,
such as a isnull, isempty etc.
--
Sajit
Abu Dhabi


"Dave Peterson" wrote:

dim myName as Name
set myname = nothing
on error resume next
set myname = ActiveWorkbook.Names(fld_name(colm))
on error goto 0

if myname is nothing then
'it doesn't exist
else
a1 = myname.refersto
end if

===
Or you could do something like:

a1 = ""
on error resume next
a1 = ActiveWorkbook.Names(fld_name(colm)).RefersTo
on error goto 0

if a1 = "" then
'something bad happened
else
'do what you want
end if



Sajit wrote:

I have the following expression in a line of code that I am writing. The
fld_name(colm) is an array of names that may be on a given sheet. The
statement results in an application defined error, since the fld_name(2) does
not exist. How do I check for the existence of a name?

I did search the general question and the programming groups, did not find a
close enough answer.

a1 = ActiveWorkbook.Names(fld_name(colm)).RefersTo
--
Sajit
Abu Dhabi


--

Dave Peterson



All times are GMT +1. The time now is 08:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com