Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Find Worksheet Name without On Error Resume Next

Is there a way to ensure a worksheet is in a workbook without using the On
Error Resume Next statement? I have the name of the worksheet, now I want to
search the workbook for that sheet, how do I do that?
--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Find Worksheet Name without On Error Resume Next

Hi Ryan

It can be done like this:

Dim IsThere As Boolean
TargetSh = "Sheet1"
For Each sh In ThisWorkbook.Sheets
If sh.Name = TargetSh Then
IsThere = True
Exit For
End If
Next
If IsThere Then
MsgBox ("Is in the workbook")
Else
MsgBox ("Is not in the workbook")
End If

Regards,
Per

"Ryan H" skrev i meddelelsen
...
Is there a way to ensure a worksheet is in a workbook without using the On
Error Resume Next statement? I have the name of the worksheet, now I want
to
search the workbook for that sheet, how do I do that?
--
Cheers,
Ryan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Find Worksheet Name without On Error Resume Next

Hi,

Someone will inevitably prove me incorrect but without using ONERROR I think
you have to loop

Dim WorksheetExists As Boolean
For x = 1 To Worksheets.Count
If Sheets(x).Name = "Sheet1" Then
WorksheetExists = True
Exit For
End If
Next
If WorksheetExists Then
MsgBox "Sheet there"
Else
MsgBox "Sheet not there"
End If

Mike

"Ryan H" wrote:

Is there a way to ensure a worksheet is in a workbook without using the On
Error Resume Next statement? I have the name of the worksheet, now I want to
search the workbook for that sheet, how do I do that?
--
Cheers,
Ryan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Find Worksheet Name without On Error Resume Next

Thats what I figured I had to do. I wasn't sure if there was a quicker way.
--
Cheers,
Ryan


"Per Jessen" wrote:

Hi Ryan

It can be done like this:

Dim IsThere As Boolean
TargetSh = "Sheet1"
For Each sh In ThisWorkbook.Sheets
If sh.Name = TargetSh Then
IsThere = True
Exit For
End If
Next
If IsThere Then
MsgBox ("Is in the workbook")
Else
MsgBox ("Is not in the workbook")
End If

Regards,
Per

"Ryan H" skrev i meddelelsen
...
Is there a way to ensure a worksheet is in a workbook without using the On
Error Resume Next statement? I have the name of the worksheet, now I want
to
search the workbook for that sheet, how do I do that?
--
Cheers,
Ryan


.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find Worksheet Name without On Error Resume Next

There's nothing wrong with the "on error resume next" approach in VBA. And it's
quicker, too.

Why wouldn't you want to use it?

Ryan H wrote:

Thats what I figured I had to do. I wasn't sure if there was a quicker way.
--
Cheers,
Ryan

"Per Jessen" wrote:

Hi Ryan

It can be done like this:

Dim IsThere As Boolean
TargetSh = "Sheet1"
For Each sh In ThisWorkbook.Sheets
If sh.Name = TargetSh Then
IsThere = True
Exit For
End If
Next
If IsThere Then
MsgBox ("Is in the workbook")
Else
MsgBox ("Is not in the workbook")
End If

Regards,
Per

"Ryan H" skrev i meddelelsen
...
Is there a way to ensure a worksheet is in a workbook without using the On
Error Resume Next statement? I have the name of the worksheet, now I want
to
search the workbook for that sheet, how do I do that?
--
Cheers,
Ryan


.


--

Dave Peterson
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
on error resume next Janis Excel Programming 1 September 19th 06 08:12 PM
On Error Resume Next Stefi Excel Programming 6 July 8th 05 11:52 AM
On Error Resume Next rcalvanese Excel Programming 3 April 11th 05 11:21 PM
ON ERROR RESUME NEXT D.S.[_3_] Excel Programming 7 December 1st 03 09:40 AM
On Error Resume Next D.S.[_3_] Excel Programming 1 November 28th 03 04:52 PM


All times are GMT +1. The time now is 01:35 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"