Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Does worksheet exist
I'm looking for a way to get a boolean result if a given
worksheet name already exists - for example if workbook text.xls contains sheet1, sheet2, and sheet3, then if I pass a variable containing the worksheet 'sheet4', I would get a false value returned. Any help would be appreciated. Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Does worksheet exist
Function SheetXist(ShName As String) As Boolean
On Error Resume Next SheetXist = Len(Sheets(ShName).Name) End Function Sub Test() MsgBox SheetXist("Sheet1") MsgBox SheetXist("Sheet4501") End Sub HTH. Best wishes Harald "Robert S" skrev i melding ... I'm looking for a way to get a boolean result if a given worksheet name already exists - for example if workbook text.xls contains sheet1, sheet2, and sheet3, then if I pass a variable containing the worksheet 'sheet4', I would get a false value returned. Any help would be appreciated. Thanks |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Does worksheet exist
From a prior posting by Chip Pearson :
Function SheetExists(SheetName As String) As Boolean On Error Resume Next SheetExists = CBool(Len(ThisWorkbook.Worksheets(SheetName).Name) ) End Function If SheetExists("Sheet1") = True Then ' do something Else ' do something else End If HTH Paul -------------------------------------------------------------------------------------------------------------- Be advised to back up your WorkBook before attempting to make changes. -------------------------------------------------------------------------------------------------------------- I'm looking for a way to get a boolean result if a given worksheet name already exists - for example if workbook text.xls contains sheet1, sheet2, and sheet3, then if I pass a variable containing the worksheet 'sheet4', I would get a false value returned. Any help would be appreciated. Thanks |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Does worksheet exist
Here is a function
'----------------------------------------------------------------- Function IsWsSheet(Sh As String, Optional WB As Workbook) As Boolean '----------------------------------------------------------------- Dim oWs As Worksheet If WB Is Nothing Then Set WB = ActiveWorkbook On Error Resume Next Set oWs = WB.Worksheets(Sh) On Error GoTo 0 IsWsSheet = Not oWs Is Nothing End Functi -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Robert S" wrote in message ... I'm looking for a way to get a boolean result if a given worksheet name already exists - for example if workbook text.xls contains sheet1, sheet2, and sheet3, then if I pass a variable containing the worksheet 'sheet4', I would get a false value returned. Any help would be appreciated. Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Does worksheet exist | Excel Discussion (Misc queries) | |||
Worksheet Sort - but all sheets in array do not exist | Excel Discussion (Misc queries) | |||
Does Worksheet Exist | Excel Discussion (Misc queries) | |||
Refrencing another cell in a worksheet that "could" exist | Excel Worksheet Functions | |||
check if a worksheet exist - VBA | Excel Programming |