• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1199
  • Last Modified:

count worksheets in a workbook in Excel

I want to count the number of worksheets contaned in an Excel workbook.  How can I do this/
2 Solutions

It's not clear how you want to use the information.  If it's within a VBA macro, then


will give you what you want.

Or, if you want the sheet count from an open workbook other than the activeworkbook:


  ( where xxxxxxx.xls = the open workbook's name)

will return the number you're looking for.

If for some reason you want the number of sheets in the workbook to appear in a worksheet cell, you can create a user-defined function that will do the job:

- Using the Visual Basic Editor, add the following code to a module:

      Function SheetsInWorkbook() As Integer
          SheetsInWorkbook = ThisWorkbook.Sheets.Count
     End Function

- save the workbook

- in a cell in your workbook, enter:

the number of sheets in the workbook will appear in that cell.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now