Solved

count worksheets in a workbook in Excel

Posted on 2011-02-19
3
1,125 Views
Last Modified: 2012-06-27
I want to count the number of worksheets contaned in an Excel workbook.  How can I do this/
0
Comment
Question by:Dier02
3 Comments
 
LVL 6

Assisted Solution

by:loopfinity
loopfinity earned 250 total points
ID: 34935326
try

wkbkobjectname.Worksheets.count
0
 
LVL 2

Accepted Solution

by:
mscanlon06851 earned 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now