Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
-----------------------------------------------------------------
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Search/Match between 2 x separate Worksheets and populate result in third worksheet | Excel Discussion (Misc queries) | |||
Copy from worksheet to another x times | Excel Discussion (Misc queries) | |||
Refrencing another cell in a worksheet that "could" exist | Excel Worksheet Functions | |||
Weekly Transaction Processing | Excel Worksheet Functions | |||
Indirect reference from one worksheet to another | Excel Worksheet Functions |