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
- Count the Number of Sheets with VBA Macro
- Video: Count the Number of Sheets
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.
#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.
#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.
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.
#2 then the “Visual Basic Editor” window will appear.
#3 click “Insert” ->”Module” to create a new module.
#4 paste the below VBA code into the code window. Then clicking “Save” button.
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.
#6 let’s see the result: