How to Count Worksheets with Specific Name in Excel?


Excel is a robust spreadsheet programme with many different features and functions. The need to determine how many worksheets in a workbook have particular names is a frequent activity. Manually numbering each sheet in a spreadsheet, no matter how big or small, can be time-consuming and error-prone. Excel thankfully offers various ways to automate this procedure and simplify your life.

You will have the skills necessary to effectively count Excel worksheets with particular names by the end of this lesson. It will provide you the skills and resources you need to complete any task, whether it be a straightforward count or work with more complicated criteria. So let's get started and discover how to count worksheets in Excel with specified names!

Count Worksheets with Specific Name

Here we will first create a VBA module and then run it to complete the task. So let us see a simple process to learn how you can count worksheets with a specific name in Excel.

Step 1

Consider an Excel workbook where you have worksheets with the same name.

First, right-click on any sheet name and select View code to open the VBA application.

Step 2

Then click on Insert and select Module, then copy the below code into the text box.

Code

Sub CountWSNames()
   Dim I As Long
   Dim xCount As Integer
   For I = 1 To ActiveWorkbook.Sheets.Count
      If Mid(Sheets(I).Name, 1, 3) = "Nir" Then xCount = xCount + 1
   Next
   MsgBox "There are " & CStr(xCount) & " sheets that start with 'Nir", vbOKOnly, "Count Worksheet Specific"
End Sub

Step 3

Then save the sheet as a macro-enabled template and click F5. Then you can see that a message will pop up.

This is how you can count worksheets with specific names in Excel.

Conclusion

In this tutorial, we have used a simple example to demonstrate how you can count worksheets with a specific name in Excel to highlight a particular set of data.

Updated on: 22-Aug-2023

98 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements