Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# count worksheets in a workbook in Excel

Posted on 2011-02-19
Medium Priority
1,179 Views
I want to count the number of worksheets contaned in an Excel workbook.  How can I do this/
0
Question by:Dier02
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 6

Assisted Solution

loopfinity earned 1000 total points
ID: 34935326
try

wkbkobjectname.Worksheets.count
0

LVL 2

Accepted Solution

mscanlon06851 earned 1000 total points
ID: 34935484
It's not clear how you want to use the information.  If it's within a VBA macro, then

thisworkbook.sheets.count

will give you what you want.

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

workbooks("xxxxxxx.xls").sheets.count

( 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:

=SheetsInWorkbook()

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

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
###### Suggested Courses
Course of the Month7 days, 8 hours left to enroll