count the sheet in a workbook

vishalvijayan

Board Regular
Joined
Dec 30, 2010
Messages
87
Hello,

I have a excel report generated from a online software. It creates a lot of separate sheets in a workbook. Is there a way to find out how many sheets are there in the workbook.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
You can try this:

Code:
Sub CountSheets()
Dim SheetNumber As Long
SheetNumber = 0
For Each ws in ActiveWorkbook.Worksheets
      SheetNumber = SheetNumber + 1
Next ws
End Sub

In this method, the variable SheetNumber will end up being however many worksheets there are. You can display this variable in any cell you want so you can see it.

Hank
 
Upvote 0
Or try:
Code:
Sub CountMySheets ()
Msgbox "Number of sheets in this workbook are: " & Activeworkbook.Worksheets.count
End Sub
Or if you want to output to a cell try:
Code:
Range("A1") = Worksheets.Count
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,629
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top