Counting Similiar Sheets

KentKHI

Active Member
Joined
Oct 1, 2004
Messages
492
Using code, how can I count all of my sheets in my active Workbook that begin with a certain letter or combination of letters (example: CO or OPT)

Thanks for any help
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
The following macro will do it:

Sub CountSheets()
Dim Criterion As String
Dim Sh As Object
Dim ShCount As Integer
ShCount = 0
Criterion = InputBox("Enter name matching criterion", _
"Count of Matching Sheet Names", "CO*")
If Criterion = "" Then Exit Sub
For Each Sh In Sheets
If Sh.Name Like Criterion Then ShCount = ShCount + 1
Next Sh
MsgBox ShCount & " sheet names match criterion", vbInformation, _
"Count Sheets Results"
End Sub


This is set up to look for sheets starting with CO (the asterisk is a wildcard character matching any number of characters after CO). To match OPT simply enter OPT* when prompted for the matching criterion.

Damon
 
Upvote 0

Forum statistics

Threads
1,207,169
Messages
6,076,908
Members
446,239
Latest member
Home Nest

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