View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default If Worksheet exists...Then run code

try this:

Function bSheetExists(wksName As String) As Boolean
' Checks if a specified worksheet exists.
'
' Arguments: wksName The name of the worksheet
'
' Returns: TRUE if the sheet exists

Dim x As Worksheet
On Error Resume Next
Set x = ActiveWorkbook.Sheets(wksName)
bSheetExists = (Err = 0)

End Function

To use:
If bSheetExists("NameOfSheet") Then...
-OR-
If Not bSheetExists("NameOfSheet") Then...

Hope this helps!
GS