Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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



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
Copy from sheet to sheet when matches criteria jeremiah Excel Worksheet Functions 2 June 2nd 09 01:05 PM
Auto Copy/autofill Text from sheet to sheet if meets criteria Joyce Excel Discussion (Misc queries) 0 November 20th 08 11:05 PM
Move data to new sheet - rename sheet based on criteria ? [email protected] Excel Discussion (Misc queries) 7 May 16th 07 10:22 PM
Need to look up value in another Sheet based on criteria in first sheet. Stacey Excel Worksheet Functions 1 March 28th 06 06:22 AM
Excel VBA (?!)-refer to a cell on Sheet to left of X, based on criteria on Sheet X tempjones Excel Programming 2 June 7th 04 09:48 PM


All times are GMT +1. The time now is 05:05 PM.

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"