How to count worksheets with specific name in Excel?
Have you ever tried to count number of worksheets whose name start with or contain specific word? For example, count the number of worksheets that name start with or contain “KTE”. This article will provide method to help you show the problem.
Count worksheets with specific name with VBA code
Quickly find all worksheets that contain specific word in sheet name
Count worksheets with specific name with VBA code
The following VBA codes help you to count number of worksheets with specific name in a workbook. Please do as follows.
1. Press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, click Insert > Module, then copy below VBA code into the Code window.
VBA code 1: Count worksheets whose name start with “KTE”
Sub CountWSNames()
Dim I As Long
Dim xCount As Integer
For I = 1 To ActiveWorkbook.Sheets.Count
If Mid(Sheets(I).Name, 1, 3) = "KTE" Then xCount = xCount + 1
Next
MsgBox "There are " & CStr(xCount) & " sheets that start with 'KTE'", vbOKOnly, "KuTools for Excel"
End Sub
If you want to count number of worksheets contain “KTE”, please apply below VBA code 2.
VBA code 2: Count worksheets whose name contain “KTE”
Sub CountWSNames()
Dim I As Long
Dim xCount As Integer
For I = 1 To ActiveWorkbook.Sheets.Count
If InStr(1, Sheets(I).Name, "KTE") > 0 Then xCount = xCount + 1
Next
MsgBox "There are " & CStr(xCount) & " sheets that with 'KTE'", vbOKOnly, "KuTools for Excel"
End Sub
Note: Please replace the word “KTE” with the one you need count number of worksheets based on.
3. Press the F5 key to run the code. Then a dialog box will pop up to tell you how many worksheets in current workbook start with “KTE” or contain “KTE”. See screenshots:
Number of worksheets whose name start with “KTE”:
Number of worksheets whose name contain “KTE”:
Quickly find all worksheets that contain specific word in sheet name.
This section will show you how to quickly find all worksheets that contain specific word in sheet name with Kutools for Excel.
Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days.
1. After installing Kutools for Excel, the Kutools’ Navigation pane will be opened automatically on the left side of workbook. Or you can enable the pane by clicking Kutools > Navigation as below screenshot shown.
2. In the Workbook & Sheet section of the navigation pane, check the Filter box and enter the specific worksheet name you with find worksheets based on. Then all worksheets whose name contain the specific word are filtered and listed in the worksheet list box. See screenshot:
If you want to have a free trial (30-day) of this utility, please click to download it, and then go to apply the operation according above steps.
Related articles:
- How to reference tab name in cell in Excel?
- How to match the cell value with sheet tab name or vice versa in Excel?
- How to open a specific worksheet by the selected value of a Combo Box in Excel?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!