Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Worksheet Exists...
How do you find out if a worksheet exists or not within a
workbook? I have some code which should only work if a worksheet (with a known name) exists in the user's workbook. Thanks. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Worksheet Exists...
James,
Try the following function: Function WorksheetExists(WSName As String, _ Optional WB As Workbook) As Boolean On Error Resume Next WorksheetExists = CBool(Len(IIf(WB Is Nothing, _ ActiveWorkbook, WB).Worksheets(WSName).Name)) End Function You can then call this in code with something like If WorksheetExists("Sheet1",ThisWorkbook) = True Then ' whatever Else ' whatever else End If -- Cordially, Chip Pearson Microsoft MVP - Excel www.cpearson.com "James Weaver" wrote in message ... How do you find out if a worksheet exists or not within a workbook? I have some code which should only work if a worksheet (with a known name) exists in the user's workbook. Thanks. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Worksheet Exists...
James,
Here's one way Dim oWS As Worksheet On Error Resume Next Set oWS = Activeworkbook.Worksheets("Sheet1") On Error GoTo 0 If oWS Is Nothing Then MsgBox "Worksheet does not exist" End If -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "James Weaver" wrote in message ... How do you find out if a worksheet exists or not within a workbook? I have some code which should only work if a worksheet (with a known name) exists in the user's workbook. Thanks. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Worksheet Exists...
Thanks - very effective!
-----Original Message----- James, Here's one way Dim oWS As Worksheet On Error Resume Next Set oWS = Activeworkbook.Worksheets("Sheet1") On Error GoTo 0 If oWS Is Nothing Then MsgBox "Worksheet does not exist" End If -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "James Weaver" wrote in message ... How do you find out if a worksheet exists or not within a workbook? I have some code which should only work if a worksheet (with a known name) exists in the user's workbook. Thanks. . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Create Worksheet BUT If It Already Exists... | Excel Discussion (Misc queries) | |||
check if worksheet exists | Excel Worksheet Functions | |||
How can I tell if a worksheet exists? | Excel Programming | |||
Test to see if a worksheet exists thanks, Chip | Excel Programming | |||
check if worksheet exists | Excel Programming |