|  

» 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 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

Rate This Tip
12 34 5
Rating: 3.81     Views: 124275
No comments have been submitted.
Click here to post comment
For Registered Users
Name
Comment Title
Comments