Use a short function that tries to reach the sheet and reports whether it worked:
Function SheetExists(sheetName As String, Optional wb As Workbook) As Boolean
Dim sh As Object
If wb Is Nothing Then Set wb = ThisWorkbook
On Error Resume Next
Set sh = wb.Sheets(sheetName)
On Error GoTo 0
SheetExists = Not sh Is Nothing
End Function
Call it before you add, delete, rename or copy a sheet, as in If SheetExists("Sales") Then. Pass a workbook to check another open file: SheetExists("Sales", Workbooks("Report.xlsx")).
The check ignores case, the same way Excel does, so “sales” finds “Sales”. A loop that compares names with = is case-sensitive and misses it, so use StrComp(sht.Name, shtName, vbTextCompare) = 0 if you loop instead.
wb.Sheets includes chart sheets. Change it to wb.Worksheets if only worksheets should count.
Without VBA, =ISREF(INDIRECT("'Sales'!A1")) returns TRUE when the sheet exists in the same file.
VBA cannot see inside a closed workbook. Open it read-only, check, and close it without saving: Set wb = Workbooks.Open("C:\Reports\Report.xlsx", ReadOnly:=True), then SheetExists("Sales", wb), then wb.Close SaveChanges:=False.
If you want to create a sheet, delete it, or move or copy it, there’s one thing that you need to know: whether that sheet exists or not.
To write code to check whether the sheet exists or not, you can use a loop that goes through each sheet in the workbook and matches the name you have provided. But here’s the thing: you can use two different loops for this (For Next and For Each), and today we will use both.
In this tutorial, we will look at different ways to do that, so make sure to have the developer tab on your ribbon and open the VBA editor to write this code.
Check IF a Sheet Exists in the Current Workbook
With this loop, you can refer to all the sheets in the workbook and loop through each one by one to match the name of the sheet with the sheet name that you want to search for.
Follow these steps:
- First, declare a variable to use for the sheet while performing the loop and to store the sheet name that you want to search.

- Next, write a line of code for an input box to enter the name of the sheet that you wish to search.

- After that, start your loop with the For Each keyword. And use the variable to refer to each worksheet in the workbook.

- From here, you need to write an IF THEN ELSE statement to match the name of the sheet with the name that you have entered in the input box, and then show a message box if a match is found and exit the procedure.

- In the end, add a message box to inform you if there’s no match.

Full Code:
Sub vba_check_sheet() Dim sht As Worksheet Dim shtName As String shtName = InputBox(Prompt:="Enter the sheet name", _ Title:="Search Sheet") For Each sht In ThisWorkbook.Worksheets If sht.Name = shtName Then MsgBox "Yes! " & shtName & " is there in the workbook." Exit Sub End If Next sht MsgBox "No! " & shtName & " is not there in the workbook." End Sub
Let me explain how this works: When you run this code, it shows you an input box where you need to enter the sheet name that you wish to find.
After that, it loops through each sheet to match the name with the name you have entered, and if the name matches a sheet, it shows you a message, and another message if there’s no match.
There are two things to keep in mind. First, this code uses ThisWorkbook.Worksheets, so it only checks worksheets in the workbook where the code is, not chart sheets. Second, the comparison is case-sensitive, so “sales” won’t match a sheet named “Sales”, even though Excel itself treats sheet names as case-insensitive. To ignore the case, use If LCase(sht.Name) = LCase(shtName) Then.
Here is another code to check if a sheet exists or not.
Sub vba_check_sheet() Dim sht As Worksheet Dim shtName As String Dim i As Long i = Sheets.Count shtName = InputBox(Prompt:="Enter the sheet name", _ Title:="Search Sheet") For i = 1 To i If Sheets(i).Name = shtName Then MsgBox "Yes! " & shtName & " is there in the workbook." Exit Sub End If Next i MsgBox "No! " & shtName & " is not there in the workbook." End Sub
This code uses the FOR NEXT loop and uses the total count of sheets in the workbook, and based on that, performs a loop through each sheet to match its name with the name you have entered. It uses Sheets, so it also checks chart sheets, and it works on the active workbook.
Check IF Sheet Exists in Closed Workbook
In the following code, you have a loop that searches for the sheet name in a closed workbook. To refer to the file, we used the file address.
Sub vba_check_sheet() Dim wb As Workbook Dim sht As Worksheet Dim shtName As String shtName = InputBox(Prompt:="Enter the sheet name", _ Title:="Search Sheet") Application.ScreenUpdating = False Set wb = Workbooks.Open _ ("C:\Users\Dell\Desktop\sample-file.xlsx") For Each sht In wb.Worksheets If sht.Name = shtName Then wb.Close SaveChanges:=False Application.ScreenUpdating = True MsgBox "Yes! " & shtName & " is there in the workbook." _ , vbInformation, "Found" Exit Sub End If Next sht wb.Close SaveChanges:=False Application.ScreenUpdating = True MsgBox "No! " & shtName _ & " is not there in the workbook.", _ vbCritical, "Not Found" End Sub
When you run this macro, it opens the file in the background as you have turned OFF screen updating, and once it loops through all the sheets, it closes the file without saving and turns ON screen updating again.
Note: As you can see, in the file location address, we have the file extension which means you need to have the correct extension of the file to refer to it.
Check IF a Sheet Exists without a Loop
You can also skip the loop and try to refer to the sheet by its name. If the sheet doesn’t exist, VBA gives an error, and you can catch it. The following function returns TRUE or FALSE, so you can use it in any macro:
Function SheetExists(shtName As String, Optional wb As Workbook) As Boolean
Dim sht As Object
If wb Is Nothing Then Set wb = ThisWorkbook
On Error Resume Next
Set sht = wb.Sheets(shtName)
On Error GoTo 0
SheetExists = Not sht Is Nothing
End Function
Put this function in a standard module. As Sheets(name) ignores the case, it finds “Sales” even if you type “sales”, and it checks chart sheets as well.
Add a Sheet Only IF It Does Not Exist
Here’s how you can use that function. The following code adds a sheet named “Summary” at the end only if there isn’t one already, which avoids the error you get when you give a new sheet a name that’s already used:
Sub add_sheet_if_missing()
If Not SheetExists("Summary") Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Summary"
Else
MsgBox "Summary is already there."
End If
End Sub
Frequently Asked Questions
Why does my code not find a sheet that is there?
Check for a difference in upper and lower case (the loop codes compare the names exactly), an extra space at the start or end of the name, and whether you are looking in the right workbook (ThisWorkbook vs ActiveWorkbook).
Can I check a sheet in a closed workbook without opening it?
Not with these simple methods. The code above opens the workbook in the background, checks the sheets, and closes it again. With screen updating turned off, you won’t see it open.
What error do I get if a sheet does not exist?
Referring to a sheet that isn’t there, like Worksheets(“Data”), gives the “Subscript out of range” error (Error 9). That’s why it’s worth checking first.
Written by
Puneet Gogia
Microsoft MVP — Excel · Founder, Excel Champs
Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.