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.
Table of Contents
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.
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.
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.
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.
Step2: then the “Visual Basic Editor” window will appear.
Step3: click “Insert” ->”Module” to create a new module.
Step4: 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
Step5: back to the current worksheet, then run the above excel macro. Click Run button.
Step6: let’s see the result:
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.