Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default how do i test for the existence of a range name

Hi rrobelen,

You can simply trap the error that may occur if it doesn't exist:

Public Function gbDoesNameExist(rwb As Workbook, _
rsName As String) As Boolean
On Error Resume Next
gbDoesNameExist = Len(rwb.Names(rsName).Name)
On Error GoTo 0
End Function

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


rrobelen wrote:
I know this must be trivial but I can't find it. How do i test to
see that a range name exists?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do i test for the existence of a range name

Thanks Marx
I thought there might be a simple test sort of like the iserror class of tests but I guess not. I thought of using this but was looking for the simple one. Thanks i am sure is more bullet proof then mine would have been. Again thanks for the quick response
Regards
Rus

----- Jake Marx wrote: ----

Hi rrobelen

You can simply trap the error that may occur if it doesn't exist

Public Function gbDoesNameExist(rwb As Workbook,
rsName As String) As Boolea
On Error Resume Nex
gbDoesNameExist = Len(rwb.Names(rsName).Name
On Error GoTo
End Functio

--
Regards

Jake Mar
MS MVP - Exce
www.longhead.co

[please keep replies in the newsgroup - email address unmonitored


rrobelen wrote
I know this must be trivial but I can't find it. How do i test t
see that a range name exists?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default how do i test for the existence of a range name

Hi Russ,

You could use the Evaluate function along with the TypeName function to see
if you have a valid range in the active workbook:

If TypeName(Evaluate("test")) = "Range" Then
MsgBox "Name found"
Else
MsgBox "Name not found"
End If

If you're looking on a specific worksheet, you can do this:

If TypeName(Workbooks("Book1.xls").Sheets("Sheet1" _
).Evaluate("test")) = "Range" Then


I prefer the On Error method in this case, as it allows more flexibility.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


rrobelen wrote:
Thanks Marx,
I thought there might be a simple test sort of like the iserror class
of tests but I guess not. I thought of using this but was looking
for the simple one. Thanks i am sure is more bullet proof then mine
would have been. Again thanks for the quick response. Regards,
Russ

----- Jake Marx wrote: -----

Hi rrobelen,

You can simply trap the error that may occur if it doesn't exist:

Public Function gbDoesNameExist(rwb As Workbook, _
rsName As String) As Boolean
On Error Resume Next
gbDoesNameExist = Len(rwb.Names(rsName).Name)
On Error GoTo 0
End Function

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address
unmonitored]


rrobelen wrote:
I know this must be trivial but I can't find it. How do i

test to see that a range name exists?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I test for nulls within a range without specifying each ce Houston Excel Discussion (Misc queries) 2 March 25th 10 05:50 PM
Test within a range? JC Excel Worksheet Functions 3 May 25th 07 03:41 AM
Formula to test for existence of external file Al at Novelis Excel Worksheet Functions 2 August 29th 06 01:13 AM
Test if Cell is within Range (name) goepf[_6_] Excel Programming 2 December 3rd 03 03:26 PM
Testing for existence of range David Excel Programming 4 November 19th 03 07:39 AM


All times are GMT +1. The time now is 05:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"