PC Review


Reply
Thread Tools Rate Thread

Check if Range EXISTS

 
 
KIM W
Guest
Posts: n/a
 
      24th May 2009
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 With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      24th May 2009
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.

 
Reply With Quote
 
AltaEgo
Guest
Posts: n/a
 
      24th May 2009

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" <(E-Mail Removed)> wrote in message
news:3C283E20-3C47-4A75-BFEC-(E-Mail Removed)...
> 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 With Quote
 
KIM W
Guest
Posts: n/a
 
      24th May 2009
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.

 
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
Check to see if a range name exists on a sheet =?Utf-8?B?U2FqaXQ=?= Microsoft Excel Programming 2 12th Oct 2007 06:32 PM
Check if text exists within a cell range and return logical vaule - possible? t9999barry@gmail.com Microsoft Excel Misc 2 20th Jul 2007 02:29 AM
Check if a named range exists with VBA? mcolson1590@gmail.com Microsoft Excel Programming 3 31st Jan 2007 06:58 PM
Check if named range exists! =?Utf-8?B?c3RldmVfZG9j?= Microsoft Excel Programming 2 29th Apr 2006 11:56 PM
Check if a number exists in a range? gkaste Microsoft Excel Misc 2 13th Jul 2005 08:00 PM


Features
 

Advertising
 

Newsgroups
 


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