Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Check if Range EXISTS

How can I verify if a range exists on a worksheet?
I am looping through all worksheets retrieving worksheet name info from a
range, but I don't want to include worksheets without the specified named
range. THe same name is used on each worksheet with scope limikted to the
worksheet.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Check if Range EXISTS

You could do something like this

Dim myRange as Excel.Range
Dim myWS as Excel.Worksheet

for each myWS in ActiveWorkbook.Worksheets
Set myRange = nothing
on error resume next
Set myRange = myWS.Range("YourRange")
On Error GoTo 0
If Not myRange is Nothing then
'Range exists
else
'Range does not exist
end if
next myWS

"KIM W" wrote:

How can I verify if a range exists on a worksheet?
I am looping through all worksheets retrieving worksheet name info from a
range, but I don't want to include worksheets without the specified named
range. THe same name is used on each worksheet with scope limikted to the
worksheet.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Check if Range EXISTS

Thank you-- this checking for range name worked just fine.
KIM W.

"Barb Reinhardt" wrote:

You could do something like this

Dim myRange as Excel.Range
Dim myWS as Excel.Worksheet

for each myWS in ActiveWorkbook.Worksheets
Set myRange = nothing
on error resume next
Set myRange = myWS.Range("YourRange")
On Error GoTo 0
If Not myRange is Nothing then
'Range exists
else
'Range does not exist
end if
next myWS

"KIM W" wrote:

How can I verify if a range exists on a worksheet?
I am looping through all worksheets retrieving worksheet name info from a
range, but I don't want to include worksheets without the specified named
range. THe same name is used on each worksheet with scope limikted to the
worksheet.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default Check if Range EXISTS


Function NmdRngExists(sRngName) As Boolean
Dim wbNamw, rngTest
On Error Resume Next
wbName = ActiveWorkbook.Name
Set rngTest = ActiveSheet.Range(sRngName)

'If there is no error then the name exists.
If Err = 0 Then

'Set the function to TRUE & exit
NmdRngExists = True
Exit Function
End If

End Function


' test by replacing myRange with your named range's name
Sub NmdRngExistsTest()
Dim sh
For Each sh In Worksheets
sh.Activate
MsgBox NmdRngExists("myRange")
Next sh
End Sub

--
Steve

"KIM W" wrote in message
...
How can I verify if a range exists on a worksheet?
I am looping through all worksheets retrieving worksheet name info from a
range, but I don't want to include worksheets without the specified named
range. THe same name is used on each worksheet with scope limikted to the
worksheet.


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
Check to see if a range name exists on a sheet Sajit Excel Programming 1 October 12th 07 06:32 PM
Check if text exists within a cell range and return logical vaule - possible? [email protected] Excel Discussion (Misc queries) 2 July 20th 07 02:29 AM
Check if a named range exists with VBA? [email protected] Excel Programming 3 January 31st 07 06:58 PM
Check if named range exists! steve_doc Excel Programming 2 April 29th 06 11:56 PM
Check if a number exists in a range? gkaste Excel Discussion (Misc queries) 2 July 13th 05 08:00 PM


All times are GMT +1. The time now is 03:54 PM.

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

About Us

"It's about Microsoft Excel"