How to Determine If a Sheet Exists Within a Workbook Using VB

104 25
    • 1). Open Microsoft Excel.

    • 2). Click "Tools," "Macro" and then click "Visual Basic." This will open the VB editor.

    • 3). Click "Insert," then "Module." You are now in a programming code module.

    • 4). Type or copy-and-paste the following code:

      Sub DoesSheetExist()

      Dim wSheet As Worksheet

      On Error Resume Next

      Set wSheet = Sheets("Sheet1")

      If wSheet Is Nothing Then

      MsgBox ("Worksheet does not exist")

      Else 'Does exist

      MsgBox ("Sheet 1 does exist")

      End If

      End Sub

    • 5). Press "F5" to run the program. It should tell you if Sheet 1 exists or does not exist in your Excel workbook.

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.