How to Count the Number of Sheets in a Workbook

,

This post will guide you how to count the number of sheets in a workbook in Excel 2013/2016/2019/365. How do I count the number of worksheets in a workbook with VBA Macro in Excel.

While manually counting the sheets is possible, it can be a tedious and time-consuming task, especially in larger workbooks. Fortunately, Excel provides several built-in functions and features that can help simplify this task. Additionally, for those who are comfortable with using VBA Macros, we will also explore a quick and easy method to count the number of sheets using a simple VBA macro.

1. Count the Number of Sheets with Define Name

If you want to count the number of worksheets in a given workbook in Excel, you can use the Defined Name and a Formula to achieve it. Just do the following steps:

 Step1: go to Formula tab, click Define Name command under Defined Names group, and the New Name dialog will open.

count worksheet number1

 Step1: type one defined name in the Name text box, such as: countWorksheets, and then type the formula =GET.WORKBOOK(1)&T(NOW()) into the text box of Refers to. Click Ok button.

count worksheet number2

 Step3: Type the following formula based on the COUNTA function and the INDEX function to get the number of worksheets in the current workbook. And press Enter key in your keyboard, you will get the number of worksheets in your workbook.

=COUNTA(INDEX(CountWorksheets,0))
count worksheet number3

2. Count the Number of Sheets with VBA Macro

You can also use an Excel VBA Macro to get the number of worksheets in the current workbook. Just do the following steps:

 Step1: open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1

 Step2: then the “Visual Basic Editor” window will appear.

 Step3: click “Insert” ->”Module” to create a new module.

convert column number to letter3

 Step4: paste the below VBA code into the code window. Then clicking “Save” button.

count worksheet number4
Sub CountWorkSheets()
    MsgBox "The number of worksheets in the current workbook is : " & Application.Sheets.Count
End Sub

 Step5: back to the current worksheet, then run the above excel macro. Click Run button.

count worksheet number5

 Step6: let’s see the result:

count worksheet number6

3. Video: Count the Number of Sheets

This video will guide you through a step-by-step process to count the number of sheets in an Excel workbook using VBA code, saving you time and effort while ensuring accuracy.

Leave a Reply