check if sheet exists if not end code

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hello, i was trying to see if there is a way to check if a sheet exists then continuing the code and if it does not then do a pop up message and end the code
the sheet is called "Users"
and it is not always there with the workbook i have code that pulls it from an external workbook, but i would like this functionality added to some other code because it would need that tab and that way i have that reminder to import that tab or even just manually create the tab incase i forget because it is one i would need to continue with other parts of my code.

Thank you!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
One way.
VBA Code:
    Dim WB As Workbook, WS As Worksheet, SheetName As String
    SheetName = "Users"
    Set WB = ActiveWorkbook
    
    On Error Resume Next
    Set WS = WB.Worksheets(SheetName)
    On Error GoTo 0
    
    If WS Is Nothing Then
        MsgBox "Worksheet '" & SheetName & "' not found in  Workbook '" & WB.Name & "'"
        Exit Sub
    End If
 
Upvote 0

Forum statistics

Threads
1,214,804
Messages
6,121,652
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top