Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Vincdc
 
Posts: n/a
Default Count the number of worksheets in a workbook

Hello:
Is there any function or other method to count the number of worksheets in a
workbook? I have a workbook which includes dozens of worksheets (each for one
client) and I would like to know the total number of clients.
Thanks in advance!
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

with VBA

Function WSNum()
WSNum = Activeworkbook.Worksheets.Count
End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Vincdc" wrote in message
...
Hello:
Is there any function or other method to count the number of worksheets in

a
workbook? I have a workbook which includes dozens of worksheets (each for

one
client) and I would like to know the total number of clients.
Thanks in advance!



  #3   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default

On Mon, 17 Jan 2005 09:07:03 -0800, Vincdc
wrote:

Hello:
Is there any function or other method to count the number of worksheets in a
workbook? I have a workbook which includes dozens of worksheets (each for one
client) and I would like to know the total number of clients.
Thanks in advance!


A VBA UDF (User Defined Function) would be best.

It is possible to use a Named formula GET.WORKBOOK(4) but this can cause
problems resulting in Excel crashing under certain circumstances.

If you are only counting Worksheets, as you write, then:

============================
Function SheetCount()
SheetCount = ActiveWorkbook.Worksheets.Count
End Function
============================

However, be aware the Charts are not Worksheets. So if you have Chart sheets
that you wish to include in the count, use:

=========================
Function SheetCount()
SheetCount = ActiveWorkbook.Sheets.Count
End Function
=======================

To enter this UDF, <alt-F11 opens the VB Editor.
Ensure your project is highlighted in the Project Explorer Window, then
Insert/Module and paste the code into the window that opens.

In some cell in the workbook, enter the formula

=SheetCount()

The cell should display the count.


--ron
  #4   Report Post  
Vincdc
 
Posts: n/a
Default

Thanks!
Just be curious, is there any built-in formula or function for this one? I
mean not the VBA code.


"Bob Phillips" wrote:

with VBA

Function WSNum()
WSNum = Activeworkbook.Worksheets.Count
End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Vincdc" wrote in message
...
Hello:
Is there any function or other method to count the number of worksheets in

a
workbook? I have a workbook which includes dozens of worksheets (each for

one
client) and I would like to know the total number of clients.
Thanks in advance!




  #5   Report Post  
Chip Pearson
 
Posts: n/a
Default

There is no built-in function to do this. You must use VBA.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Vincdc" wrote in message
...
Thanks!
Just be curious, is there any built-in formula or function for
this one? I
mean not the VBA code.


"Bob Phillips" wrote:

with VBA

Function WSNum()
WSNum = Activeworkbook.Worksheets.Count
End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Vincdc" wrote in message
...
Hello:
Is there any function or other method to count the number of
worksheets in

a
workbook? I have a workbook which includes dozens of
worksheets (each for

one
client) and I would like to know the total number of
clients.
Thanks in advance!








  #6   Report Post  
Bob Phillips
 
Posts: n/a
Default

You could create a workbook name, say NumSheets, with a refers to value of
=GET.WORKBOOK(4) , and then use =NumSheets in the worksheet. But be warned,
if you copy this cell in any Excel version prior to XL2002, it causes an
Excel crash. so I advise against it.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Vincdc" wrote in message
...
Thanks!
Just be curious, is there any built-in formula or function for this one? I
mean not the VBA code.


"Bob Phillips" wrote:

with VBA

Function WSNum()
WSNum = Activeworkbook.Worksheets.Count
End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Vincdc" wrote in message
...
Hello:
Is there any function or other method to count the number of

worksheets in
a
workbook? I have a workbook which includes dozens of worksheets (each

for
one
client) and I would like to know the total number of clients.
Thanks in advance!






  #7   Report Post  
Vincdc
 
Posts: n/a
Default

Really thanks for all your help! :=)

"Ron Rosenfeld" wrote:

On Mon, 17 Jan 2005 09:07:03 -0800, Vincdc
wrote:

Hello:
Is there any function or other method to count the number of worksheets in a
workbook? I have a workbook which includes dozens of worksheets (each for one
client) and I would like to know the total number of clients.
Thanks in advance!


A VBA UDF (User Defined Function) would be best.

It is possible to use a Named formula GET.WORKBOOK(4) but this can cause
problems resulting in Excel crashing under certain circumstances.

If you are only counting Worksheets, as you write, then:

============================
Function SheetCount()
SheetCount = ActiveWorkbook.Worksheets.Count
End Function
============================

However, be aware the Charts are not Worksheets. So if you have Chart sheets
that you wish to include in the count, use:

=========================
Function SheetCount()
SheetCount = ActiveWorkbook.Sheets.Count
End Function
=======================

To enter this UDF, <alt-F11 opens the VB Editor.
Ensure your project is highlighted in the Project Explorer Window, then
Insert/Module and paste the code into the window that opens.

In some cell in the workbook, enter the formula

=SheetCount()

The cell should display the count.


--ron

  #8   Report Post  
Dave Peterson
 
Posts: n/a
Default

I'm not sure if it's important, but this version will calculate the number of
worksheets in the workbook with the formula.


Option Explicit
Function WSNum()
WSNum = Application.Caller.Parent.Parent.Worksheets.Count
End Function

Application.caller is the cell containing the formula.
its parent is the worksheet.
the worksheet's parent is the workbook.

If you open two workbooks (each with a different number of worksheets in them)
and use window|arrange|horizontal.

You should be able to notice the difference.

Vincdc wrote:

Hello:
Is there any function or other method to count the number of worksheets in a
workbook? I have a workbook which includes dozens of worksheets (each for one
client) and I would like to know the total number of clients.
Thanks in advance!


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slow opening Excel Workbook with over 50 Worksheets KathyRice Excel Discussion (Misc queries) 1 January 4th 05 11:49 PM
How do I create repeating worksheets in one workbook and have it . DM HD Excel Discussion (Misc queries) 8 December 23rd 04 06:49 PM
Count number of shaded cells Maddoktor Excel Discussion (Misc queries) 2 December 20th 04 08:35 PM
count formula between worksheets Seti Excel Discussion (Misc queries) 3 December 9th 04 09:25 PM
Removing links to other worksheets from within a workbook rjb Excel Discussion (Misc queries) 2 December 9th 04 08:04 AM


All times are GMT +1. The time now is 07:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"