#1   Report Post  
BillCPA
 
Posts: n/a
Default Does Worksheet Exist

Is there a quick and easy statement to use (in VBA) to check and see if a
particular worksheet exists (by name)?

--
Bill @ UAMS
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

-----------------------------------------------------------------
Function SheetExists(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
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)


"BillCPA" <Bill @ UAMS wrote in message
...
Is there a quick and easy statement to use (in VBA) to check and see if a
particular worksheet exists (by name)?

--
Bill @ UAMS



  #3   Report Post  
Harald Staff
 
Posts: n/a
Default

It's prettty easy to write. Here's one solution:

Sub test()
MsgBox SheetXists("Sheet1")
MsgBox SheetXists("Rumsfeld Quotes")
End Sub

Function SheetXists(SheetName As String) As Boolean
On Error Resume Next
SheetXists = Len(Sheets(SheetName).Name)
End Function

HTH. Best wishes Harald

"BillCPA" <Bill @ UAMS skrev i melding
...
Is there a quick and easy statement to use (in VBA) to check and see if a
particular worksheet exists (by name)?

--
Bill @ UAMS



  #4   Report Post  
BillCPA
 
Posts: n/a
Default

Thanks - I'm still a little fuzzy on creating functions.

"Harald Staff" wrote:

It's prettty easy to write. Here's one solution:

Sub test()
MsgBox SheetXists("Sheet1")
MsgBox SheetXists("Rumsfeld Quotes")
End Sub

Function SheetXists(SheetName As String) As Boolean
On Error Resume Next
SheetXists = Len(Sheets(SheetName).Name)
End Function

HTH. Best wishes Harald

"BillCPA" <Bill @ UAMS skrev i melding
...
Is there a quick and easy statement to use (in VBA) to check and see if a
particular worksheet exists (by name)?

--
Bill @ UAMS




  #5   Report Post  
BillCPA
 
Posts: n/a
Default

Thanks - I'm still a little fuzzy on creating functions.

"Bob Phillips" wrote:

-----------------------------------------------------------------
Function SheetExists(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
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)


"BillCPA" <Bill @ UAMS wrote in message
...
Is there a quick and easy statement to use (in VBA) to check and see if a
particular worksheet exists (by name)?

--
Bill @ UAMS






  #6   Report Post  
Bob Phillips
 
Posts: n/a
Default

Same as sub, just call it differently.

If SheetExists("My Summary Page") Then
'do something
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"BillCPA" <Bill @ UAMS wrote in message
...
Thanks - I'm still a little fuzzy on creating functions.

"Bob Phillips" wrote:

-----------------------------------------------------------------
Function SheetExists(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
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)


"BillCPA" <Bill @ UAMS wrote in message
...
Is there a quick and easy statement to use (in VBA) to check and see

if a
particular worksheet exists (by name)?

--
Bill @ UAMS






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
Search/Match between 2 x separate Worksheets and populate result in third worksheet Alan Bartley Excel Discussion (Misc queries) 1 April 11th 05 05:21 AM
Copy from worksheet to another x times Union70 Excel Discussion (Misc queries) 0 March 7th 05 09:03 PM
Refrencing another cell in a worksheet that "could" exist KimberlyC Excel Worksheet Functions 1 February 7th 05 07:09 PM
Weekly Transaction Processing Ralph Howarth Excel Worksheet Functions 4 January 19th 05 05:37 AM
Indirect reference from one worksheet to another Bill Sturdevant Excel Worksheet Functions 2 December 17th 04 01:23 PM


All times are GMT +1. The time now is 11:29 AM.

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"