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. How do I count the number of worksheets in a workbook with VBA Macro in Excel.

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:

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

 count worksheet number1

#2 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

#3 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   

 

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:

#1 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

#2 then the “Visual Basic Editor” window will appear.

#3 click “Insert” ->”Module” to create a new module.

convert column number to letter3

#4 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

#5 back to the current worksheet, then run the above excel macro. Click Run button.

count worksheet number5

#6 let’s see the result:

count worksheet number6

Video: Count the Number of Sheets

 

 

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar