» Determine if a sheet exists in a workbook using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Files, Workbook, and Worksheets in VBA
VERSION - All Microsoft Excel Versions
The function below can be used to determine if a sheet exists in a workbook:
Function SheetExists(SheetName As String) As Boolean
' returns TRUE if the sheet exists in the active workbook
SheetExists = False
On Error GoTo NoSuchSheet
If Len(Sheets(SheetName).Name) > 0 Then
SheetExists = True
Exit Function
End If
NoSuchSheet:
End Function
Example:
If Not SheetExists("MySheetName") Then
MsgBox "MySheetName doesn't exist!"
Else
Sheets("MySheetName").Activate
End If
Book Store:
Recommended Books:
- Microsoft Excel 2002 Formulas (With CD-ROM)
- Financial Risk Manager Handbook, Second Edition
- Monte Carlo Methods in Finance
- Financial Statement Analysis: A Practitioner's Guide, 3rd Edition
- Business Plans Kit for Dummies (With CD-ROM)
- The McGraw-Hill 36-Hour Course in Finance for Nonfinancial Managers
No comments have been submitted.

