PC Review


Reply
Thread Tools Rate Thread

Check if a named range exists with VBA?

 
 
mcolson1590@gmail.com
Guest
Posts: n/a
 
      30th Jan 2007
I am trying to see if a named range exists with VBA. In my
subroutine, I browse for and then open another Excel file. I then set
ranges on that sheet = to defined variables. I would like to verify
that these ranges exist on that sheet before trying to set them (in
order to avoid an error in running). For example, does that sheet
have a named range "Name"?

Thanks for any help,

Matt

 
Reply With Quote
 
 
 
 
Trevor Shuttleworth
Guest
Posts: n/a
 
      30th Jan 2007
Matt

Chip Pearson describes Named Ranges at:

http://www.cpearson.com/excel/named.htm

Regards

Trevor


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am trying to see if a named range exists with VBA. In my
> subroutine, I browse for and then open another Excel file. I then set
> ranges on that sheet = to defined variables. I would like to verify
> that these ranges exist on that sheet before trying to set them (in
> order to avoid an error in running). For example, does that sheet
> have a named range "Name"?
>
> Thanks for any help,
>
> Matt
>



 
Reply With Quote
 
Skip
Guest
Posts: n/a
 
      30th Jan 2007

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am trying to see if a named range exists with VBA. In my
> subroutine, I browse for and then open another Excel file. I then set
> ranges on that sheet = to defined variables. I would like to verify
> that these ranges exist on that sheet before trying to set them (in
> order to avoid an error in running). For example, does that sheet
> have a named range "Name"?
>
> Thanks for any help,
>
> Matt
>



Try this function. You have to supply the range name you are interested in,
it returns True/False

Public Function RangeNameExists(argRangeName As String) As Boolean
' Returns TRUE if the range name exists
' Include the sheet name in argRangeName.
' i.e. "Sunday!freezer25" where the sheet name is Sunday and the range
name is freezer25
Dim n As Name
RangeNameExists = False
For Each n In ActiveWorkbook.Names
If UCase(n.Name) = UCase(argRangeName) Then
RangeNameExists = True
Exit Function
End If
Next n
End Function


 
Reply With Quote
 
mcolson
Guest
Posts: n/a
 
      31st Jan 2007
On Jan 30, 5:41 pm, "Skip" <skipper1...@yahoo.com> wrote:
> <mcolson1...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
> > I am trying to see if anamedrange exists with VBA. In my
> > subroutine, I browse for and then open another Excel file. I then set
> >rangeson that sheet = to defined variables. I would like to verify
> > that theserangesexiston that sheet before trying to set them (in
> > order to avoid an error in running). For example, does that sheet
> > have anamedrange "Name"?

>
> > Thanks for any help,

>
> > Matt

>
> Try this function. You have to supply the range name you are interested in,
> it returns True/False
>
> Public Function RangeNameExists(argRangeName As String) As Boolean
> ' Returns TRUE if the range name exists
> ' Include the sheet name in argRangeName.
> ' i.e. "Sunday!freezer25" where the sheet name is Sunday and the range
> name is freezer25
> Dim n As Name
> RangeNameExists = False
> For Each n In ActiveWorkbook.Names
> If UCase(n.Name) = UCase(argRangeName) Then
> RangeNameExists = True
> Exit Function
> End If
> Next n
> End Function


That worked great.

 
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
Directory Name - IF Named Range Exists lilanngel Microsoft Excel Programming 0 23rd Feb 2010 05:29 PM
Check if named range exists! =?Utf-8?B?c3RldmVfZG9j?= Microsoft Excel Programming 2 29th Apr 2006 11:56 PM
Determining if a named range exists a Microsoft Excel Programming 2 5th Jan 2006 01:39 PM
Validate Named Range Exists =?Utf-8?B?Sm9obiBKb3N0?= Microsoft Excel Programming 5 5th Dec 2005 08:17 PM
how to tell if a named range exists =?Utf-8?B?R2l4eGVyX0pfOTc=?= Microsoft Excel Programming 2 1st Jun 2005 07:38 PM


Features
 

Advertising
 

Newsgroups
 


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