PC Review


Reply
Thread Tools Rate Thread

Checking if worksheet exsits

 
 
treasuresflemar
Guest
Posts: n/a
 
      4th Dec 2007
I have
Dim rn as string ' contains name of worksheet
Dim rs as string , contains name of named range

How do I check to see if worksheet rn exists
and named range rs?
Currently trapping err.number but got to be a better way.

Thanks


 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      4th Dec 2007


Found = False
for each ws in Thisworkbook.sheets
if ws.name = rn then
Found = True
exit for
end if
next ws
if found = True then
' enter your code here

end if
Found = False
For Each nm In ActiveWorkbook.Names
If rs = nm.Name Then
found = True
Exit For
End If
Next
If found = True Then
'enter your code here
End If


"treasuresflemar" wrote:

> I have
> Dim rn as string ' contains name of worksheet
> Dim rs as string , contains name of named range
>
> How do I check to see if worksheet rn exists
> and named range rs?
> Currently trapping err.number but got to be a better way.
>
> Thanks
>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      4th Dec 2007

On Error Resume Next
Set sh = Worksheets(rn)
On Error Goto 0
If Not sh Is Nothing Then
...

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"treasuresflemar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have
> Dim rn as string ' contains name of worksheet
> Dim rs as string , contains name of named range
>
> How do I check to see if worksheet rn exists
> and named range rs?
> Currently trapping err.number but got to be a better way.
>
> Thanks
>
>



 
Reply With Quote
 
john
Guest
Posts: n/a
 
      4th Dec 2007
Couple of simple ideas:

Sub CheckSheet()
On Error Resume Next
If Worksheets("Sheet2") Is Nothing Then
MsgBox "Sheet Does Not Exist"
Else
MsgBox "Sheet Already Exists"
End If
On Error GoTo 0
End Sub

Sub CheckNames()
Set wbn = ActiveWorkbook.Names
For r = 1 To wbn.Count
If wbn(r).Name = "Test" Then
MsgBox "Name Exists"
End If
Next
End Sub
--
JB


"treasuresflemar" wrote:

> I have
> Dim rn as string ' contains name of worksheet
> Dim rs as string , contains name of named range
>
> How do I check to see if worksheet rn exists
> and named range rs?
> Currently trapping err.number but got to be a better way.
>
> Thanks
>
>
>

 
Reply With Quote
 
Frederik
Guest
Posts: n/a
 
      5th Dec 2007
Perhaps have a look at

http://www.j-walk.com/ss/excel/tips/tip54.htm

a very valuable source of information!

greetz

"treasuresflemar" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
>I have
> Dim rn as string ' contains name of worksheet
> Dim rs as string , contains name of named range
>
> How do I check to see if worksheet rn exists
> and named range rs?
> Currently trapping err.number but got to be a better way.
>
> Thanks
>
>



 
Reply With Quote
 
treasuresflemar
Guest
Posts: n/a
 
      6th Dec 2007
Thnaks just what the doctor ordered.

"Frederik" <(E-Mail Removed)> wrote in message
news:8Xu5j.240471$(E-Mail Removed)...
> Perhaps have a look at
>
> http://www.j-walk.com/ss/excel/tips/tip54.htm
>
> a very valuable source of information!
>
> greetz
>
> "treasuresflemar" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
>>I have
>> Dim rn as string ' contains name of worksheet
>> Dim rs as string , contains name of named range
>>
>> How do I check to see if worksheet rn exists
>> and named range rs?
>> Currently trapping err.number but got to be a better way.
>>
>> Thanks
>>
>>

>
>



 
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
Checking a worksheet is present =?Utf-8?B?bW1jMzA4?= Microsoft Excel Programming 5 21st May 2007 08:59 AM
Checking for existing worksheet name KtM Microsoft Excel Programming 3 15th Dec 2005 12:21 PM
Checking whether a worksheet exist or not ajitpalsingh200 Microsoft Excel Programming 0 10th Nov 2004 05:44 AM
checking if worksheet is blank Tommi Microsoft Excel Programming 1 2nd Nov 2003 03:59 PM
Checking if worksheet is blank Tommi Microsoft Excel Programming 3 31st Oct 2003 02:22 PM


Features
 

Advertising
 

Newsgroups
 


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