Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
check if sheet exists | Excel Discussion (Misc queries) | |||
Check Activesheet for chart sheet or work sheet | Charts and Charting in Excel | |||
Enable check box in protected sheet + group check boxes | Excel Discussion (Misc queries) | |||
how to use sumif function to check date in 1 sheet is < 2 sheet | Excel Worksheet Functions | |||
Check changes on a sheet | Excel Programming |