Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Checking if worksheet exsits

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Checking if worksheet exsits



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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Checking if worksheet exsits


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" wrote in message
...
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Checking if worksheet exsits

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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Checking if worksheet exsits

Perhaps have a look at

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

a very valuable source of information!

greetz

"treasuresflemar" schreef in bericht
...
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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Checking if worksheet exsits

Thnaks just what the doctor ordered.

"Frederik" wrote in message
...
Perhaps have a look at

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

a very valuable source of information!

greetz

"treasuresflemar" schreef in bericht
...
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
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
Checking a worksheet is present mmc308 Excel Programming 5 May 21st 07 08:59 AM
Checking whether a worksheet exist or not ajitpalsingh200[_18_] Excel Programming 0 November 10th 04 05:44 AM
Checking whether a worksheet exist or not ajitpalsingh200[_17_] Excel Programming 4 November 9th 04 01:30 PM
worksheet error checking AlexD Excel Programming 4 March 4th 04 12:45 AM
Checking if worksheet is blank Tommi[_2_] Excel Programming 3 October 31st 03 02:22 PM


All times are GMT +1. The time now is 08:25 PM.

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"