Counting sheets in a workbook.

D

Danny

Please help me with a command to count the number of
sheets in a workbook. Thanks!
 
J

Jason Morin

Try this macro:

Sub Count_WS()
Dim a As Integer
a = ActiveWorkbook.Worksheets.Count
MsgBox a & " worksheets"
End Sub
 
K

Ken Wright

And just in case you want to count chart sheets as well, with a slight tweak on Jason's code:-

Sub Count_WS()

Dim a As Integer
a = ActiveWorkbook.Worksheets.Count
b = ActiveWorkbook.Charts.Count
MsgBox a & " Worksheets, " & b & " Chart Sheets"

End Sub

or if you wanted it all lumped together, including any chart sheets

Sub Count_WS()
Dim a As Integer
a = ActiveWorkbook.Sheets.Count
MsgBox a & " Sheets"

End Sub
 
D

Danny

Ken,
This macro helps me a lot too! I was "manually" counting
my chart sheets. Thanks a lot!
Danny
-----Original Message-----
And just in case you want to count chart sheets as well,
with a slight tweak on Jason's code:-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top