Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
carlos sosa
 
Posts: n/a
Default excel should have a function to count sheets

excel doesn't have a function to count sheets in a book. i think it is useful
when a result depends on the number of sheets you have in a book. for
example, i would like to number the pages 1 of 3, 2 of 3 and 3 of 3
automaticaly and it is imposible if excel is no able to count sheets unless
you use a macro with visual basic.
  #3   Report Post  
Fredrik Wahlgren
 
Posts: n/a
Default

If you want a function, you have to roll your own. Select Tools|Visual basic
Editor... insert a new module and paste the code below

Public Function GetSheetCount() As Long
GetSheetCount= ActiveWorkbook.Worksheets.Count
End Function

You can now enter =GetSheetCount() in a cell and it will return the # of
sheets in your workbook

/Fredrik

"Steve R" wrote in message
...
How about:

Sub NumSheets()

TotSheets = Worksheets.Count

i = 1
For Each sh In Worksheets
sh.Name = i & " of " & TotSheets
i = i + 1
Next sh

End Sub


"carlos sosa" <carlos wrote in message
...
excel doesn't have a function to count sheets in a book. i think it is
useful
when a result depends on the number of sheets you have in a book. for
example, i would like to number the pages 1 of 3, 2 of 3 and 3 of 3
automaticaly and it is imposible if excel is no able to count sheets
unless
you use a macro with visual basic.





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

A more robust solution, in case the user has multiple workbooks
open, would be the following:

Public Function GetSheetCount() As Long
GetSheetCount =
Application.Caller.Parent.Parent.Worksheets.Count
End Function


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




"Fredrik Wahlgren" wrote
in message ...
If you want a function, you have to roll your own. Select
Tools|Visual basic
Editor... insert a new module and paste the code below

Public Function GetSheetCount() As Long
GetSheetCount= ActiveWorkbook.Worksheets.Count
End Function

You can now enter =GetSheetCount() in a cell and it will return
the # of
sheets in your workbook

/Fredrik

"Steve R" wrote in
message
...
How about:

Sub NumSheets()

TotSheets = Worksheets.Count

i = 1
For Each sh In Worksheets
sh.Name = i & " of " & TotSheets
i = i + 1
Next sh

End Sub


"carlos sosa" <carlos wrote in
message
...
excel doesn't have a function to count sheets in a book. i
think it is
useful
when a result depends on the number of sheets you have in a
book. for
example, i would like to number the pages 1 of 3, 2 of 3 and
3 of 3
automaticaly and it is imposible if excel is no able to
count sheets
unless
you use a macro with visual basic.







  #5   Report Post  
JulieD
 
Posts: n/a
Default

Hi

you could also use the Report Manager add-in (ver 2000 tools / addins / tick
report manager and then you'll find it under the insert menu) with ver
2002/2003 check out MS's site for it ... if you can't find it post back and
i'll dig out the web page address

--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"carlos sosa" <carlos wrote in message
...
excel doesn't have a function to count sheets in a book. i think it is
useful
when a result depends on the number of sheets you have in a book. for
example, i would like to number the pages 1 of 3, 2 of 3 and 3 of 3
automaticaly and it is imposible if excel is no able to count sheets
unless
you use a macro with visual basic.





  #6   Report Post  
Harlan Grove
 
Posts: n/a
Default

carlos sosa wrote...
excel doesn't have a function to count sheets in a book. i think it is

useful
when a result depends on the number of sheets you have in a book. for


example, i would like to number the pages 1 of 3, 2 of 3 and 3 of 3
automaticaly and it is imposible if excel is no able to count sheets

unless
you use a macro with visual basic.


Uh . . . why not use Page Setup headers or footers containing

&[Page] of &[Pages]

?

  #7   Report Post  
Brandon
 
Posts: n/a
Default

Did you ever happen to get a full answer to this? I'm having the same issue.
The reply that allows you to create the insertable "getsheetcount" function
works for the total pages issue, but what about the "1 of x", "2 of x" issue?
Is there a macro to create a function in a cell to identify the sheet you're
on, insert the "of" in between, and then show the total number of sheets?

"carlos sosa" wrote:

excel doesn't have a function to count sheets in a book. i think it is useful
when a result depends on the number of sheets you have in a book. for
example, i would like to number the pages 1 of 3, 2 of 3 and 3 of 3
automaticaly and it is imposible if excel is no able to count sheets unless
you use a macro with visual basic.

  #8   Report Post  
Vasant Nanavati
 
Posts: n/a
Default

Maybe I'm missing something, but you can do this very easily in a footer.
It's somewhat complicated (and not foolproof) to do it using a formula in a
cell.

--

Vasant

"Brandon" wrote in message
...
Did you ever happen to get a full answer to this? I'm having the same

issue.
The reply that allows you to create the insertable "getsheetcount"

function
works for the total pages issue, but what about the "1 of x", "2 of x"

issue?
Is there a macro to create a function in a cell to identify the sheet

you're
on, insert the "of" in between, and then show the total number of sheets?

"carlos sosa" wrote:

excel doesn't have a function to count sheets in a book. i think it is

useful
when a result depends on the number of sheets you have in a book. for
example, i would like to number the pages 1 of 3, 2 of 3 and 3 of 3
automaticaly and it is imposible if excel is no able to count sheets

unless
you use a macro with visual basic.



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
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? Richard Excel Discussion (Misc queries) 2 May 13th 23 11:46 AM
COUNT over several sheets Fybo Excel Discussion (Misc queries) 6 March 8th 05 04:40 PM
count dates in excel skchth Excel Discussion (Misc queries) 6 March 3rd 05 12:35 AM
how can i link sheets in my excel workbook new secretary Excel Worksheet Functions 1 December 31st 04 10:08 PM
Excel Sort function should not sort the cell formatting! Lisa D.N.1 Excel Worksheet Functions 1 December 28th 04 08:37 PM


All times are GMT +1. The time now is 03:45 AM.

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

About Us

"It's about Microsoft Excel"