PC Review


Reply
Thread Tools Rate Thread

Check to see if a range name exists on a sheet

 
 
=?Utf-8?B?U2FqaXQ=?=
Guest
Posts: n/a
 
      12th Oct 2007
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
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      12th Oct 2007
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
 
Reply With Quote
 
=?Utf-8?B?U2FqaXQ=?=
Guest
Posts: n/a
 
      12th Oct 2007
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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I check to see if a sheet exists? Cruzian_Rain Girl Microsoft Excel Programming 5 15th Dec 2008 11:07 AM
check if sheet exists mohavv Microsoft Excel Misc 1 21st Nov 2007 01:58 AM
check if the sheet/tag exists =?Utf-8?B?QWxleA==?= Microsoft Excel Worksheet Functions 2 14th Mar 2006 08:58 PM
check to see if sheet exists Wandering Mage Microsoft Excel Programming 1 28th Sep 2004 07:53 PM
Check if a sheet exists Jon Microsoft Excel Misc 4 6th May 2004 08:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:42 AM.