» 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
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:
- Learn MS Excel 2002 VBA/XML Programming
- Mastering Excel 2000 (for beginner)
- Real Estate Loopholes: Secrets of Successful Real Estate Investing
- Managerial Accounting: Tools for Business Decision Making, WebCT, 2nd Edition
- Your First Business Plan: A Simple Question and Answer Format Designed to Help You Write Your Own Plan (3rd Ed)
- Understanding Financial Statements
No comments have been submitted.

