Why does this COUNT macro not work

velohead

Board Regular
Joined
Aug 22, 2007
Messages
212
Hi All,

I have two macros, the first macro works perfectly, the second macro does not work at all (error message).
What is wrong with the second macro, please.

Code:
Sub This_Works_For_Workbook()
MsgBox ActiveWorkbook.Styles.Count
End Sub
Sub This_Does_Not_Work_For_Worksheet()
MsgBox ActiveSheet.Styles.Count
End Sub

The macro is supposed to count styles used, as excel has a limit of 64,000 styles else the "TOO MANY DIFFERENT CELL FORMATS" message pops up when attempting yet another font size (for example).
Yes, I have inherited a file with too many cell formats, Doh!
I just want to count the cell formats in one worksheet, so I know which to give priority.

If someone has the time to list worksheets with a style count, I would not dissuade them, although I do not expect that of course.

Thank You All
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hello there

Unfortunately there is no styles object for the worksheet object, only for the workbook object, hence why it doesnt work.
 
Upvote 0
You could loop through each tab copying each to a new workbook, counting the styles and then closing the newly created workbook without saving. Seems a lot of work though.
 
Upvote 0
It's a possibility that I had not considered.

Seems a lot of work - but would extend my VBA knowledge though.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

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