![]() |
Sheet Criteria
Hi
If the sheet (chart 1) does not exist in my workbook then I would like to run my macro, otherwise not. How can I search the book to see if the chart1 sheet exists? Many thanks Kerry |
Sheet Criteria
'----------------------------------------------------------------- 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.Sheets(Sh) Is Nothing) On Error GoTo 0 End Function ?SheetExists("Chart1") -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "Kerry Purdy" wrote in message ... Hi If the sheet (chart 1) does not exist in my workbook then I would like to run my macro, otherwise not. How can I search the book to see if the chart1 sheet exists? Many thanks Kerry |
Sheet Criteria
Kerry,
Try something like Dim SH As Object On Error Resume Next Set SH = Sheets("Chart1") If SH Is Nothing Then Debug.Print "Sheet does not exist" Else Debug.Print "Sheet exists." End If -- Cordially, Chip Pearson Microsoft MVP - Excel www.cpearson.com (email address is on the web site) "Kerry Purdy" wrote in message ... Hi If the sheet (chart 1) does not exist in my workbook then I would like to run my macro, otherwise not. How can I search the book to see if the chart1 sheet exists? Many thanks Kerry |
All times are GMT +1. The time now is 05:14 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com