Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Check for sheet name

How would I check to see if there is a sheet named "Sheet1" in the active
workbook.

Sub CheckFor New Sheet()

If sheets("Sheet1") does not exist in this WB Then
MsgBox ("No sheet has been added")
Exit Sub
Else
End If

continue...

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Check for sheet name

Mike

What you need to do is to loop through the worksheets collection,
while looking at each worksheets name. The following code should serve
as an example

Sub FindASheet()

' Local Variables
Dim wks As Worksheet
Dim blnWksPresent As Boolean

For Each wks In Application.Worksheets
If wks.Name = "Feed Sheet (1)" Then
blnWksPresent = True
End If
Next wks
If Not blnWksPresent Then Exit Sub

End Sub




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Check for sheet name

Mike,

Here's another method:

Sub test()

Dim sh As Worksheet

On Error Resume Next
Set sh = ActiveWorkbook.Worksheets("Sheet1")
If Err < 0 Then
MsgBox "no Sheet1"
Else
MsgBox "Sheet1 exists"
End If
On Error GoTo 0

End Sub

hth,

Doug

"Mike Fogleman" wrote in message
...
How would I check to see if there is a sheet named "Sheet1" in the active
workbook.

Sub CheckFor New Sheet()

If sheets("Sheet1") does not exist in this WB Then
MsgBox ("No sheet has been added")
Exit Sub
Else
End If

continue...

End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Check for sheet name

Chip gave this as an answer once I thought it was about as short as
possible.

Function WorksheetExists(WSName As String, Optional WB As Workbook =
Nothing) As Boolean
On Error Resume Next
WorksheetExists = CBool(Len(IIf(WB Is Nothing, ThisWorkbook,
WB).Worksheets(WSName).Name))
End Function

--
Regards,
Rocky McKinley


"Mike Fogleman" wrote in message
...
How would I check to see if there is a sheet named "Sheet1" in the active
workbook.

Sub CheckFor New Sheet()

If sheets("Sheet1") does not exist in this WB Then
MsgBox ("No sheet has been added")
Exit Sub
Else
End If

continue...

End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Check for sheet name

Thanks guys, a loop worked fine because there can only be 1 or 2 sheets
total in the book.
"Mike Fogleman" wrote in message
...
How would I check to see if there is a sheet named "Sheet1" in the active
workbook.

Sub CheckFor New Sheet()

If sheets("Sheet1") does not exist in this WB Then
MsgBox ("No sheet has been added")
Exit Sub
Else
End If

continue...

End Sub




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 if sheet exists mohavv Excel Discussion (Misc queries) 1 November 21st 07 01:58 AM
Check Activesheet for chart sheet or work sheet NSK Charts and Charting in Excel 1 July 17th 07 09:00 PM
Enable check box in protected sheet + group check boxes Dexxterr Excel Discussion (Misc queries) 4 August 2nd 06 12:00 PM
how to use sumif function to check date in 1 sheet is < 2 sheet Bharat Saboo Excel Worksheet Functions 3 December 30th 05 07:10 AM
Check changes on a sheet Lorenzo Excel Programming 3 August 7th 03 10:53 PM


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