![]() |
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 |
-----------------------------------------------------------------
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 |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 11:09 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com