Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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
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
Does worksheet exist BB Ivan Excel Discussion (Misc queries) 1 January 29th 09 10:04 PM
Worksheet Sort - but all sheets in array do not exist [email protected] Excel Discussion (Misc queries) 2 August 20th 06 02:41 AM
Does Worksheet Exist BillCPA Excel Discussion (Misc queries) 5 April 19th 05 11:22 PM
Refrencing another cell in a worksheet that "could" exist KimberlyC Excel Worksheet Functions 1 February 7th 05 07:09 PM
check if a worksheet exist - VBA Warren Excel Programming 1 September 10th 03 05:02 AM


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