ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sheet Criteria (https://www.excelbanter.com/excel-programming/375569-sheet-criteria.html)

Kerry Purdy

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

Bob Phillips

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




Chip Pearson

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