VBA Code to Check if Worksheet Exists in Excel

This code checks if a worksheet with a specific name exists in the workbook.

VBA Code:

Function WorksheetExists(ByVal worksheetName As String) As Boolean
    Dim ws As Worksheet
    On Error Resume Next
    Set ws = Worksheets(worksheetName)
    On Error GoTo 0
    WorksheetExists = Not ws Is Nothing
End Function
Join Our Telegram Group techguruplus telegram group Join Our WhatsApp Group techguruplus whatsapp group

Leave a Comment