Count chartbjects from multiple sheets in a excel file

Sagar0650

Board Regular
Joined
Nov 25, 2019
Messages
55
Office Version
  1. 2019
Platform
  1. Windows
I have 3 charts in three different sheets in excel workbook.
I want to count the number of charts present in excel workbook.
I have tried activesheet.chartobjects.count
It gives the count of charts present in that particular sheet.
Can anyone has solution to count all the charts present across the whole workbook?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
something like....

Code:
sub countem()
dim ws as worksheet
dim ctr as integer

for each ws in ThisWorkbook
     ctr = ctr + activesheet.chartobjects.count
next ws

end sub
 
Upvote 0
Thank you Richard for quick response.

for each ws in worksheets
ctr = ctr + activesheet.chartobjects.count
next ws

this code worked for me
again thank you for helping me out
much appreciated
 
Upvote 0
YW, Please feel free to reach out to me any time.
 
Upvote 0
Sure Richard.
thank you
Yeah, that should have been for each ws in thisworkbook.worksheets

Sorry about that. glad I could steer you in the right direction though.

BTW, always be explicit in your code If multiple sheets/workbooks are open, you can get strange results.

So, for example, I typically do something like.

Dim wb as workbook
dim ws as worksheet
dim ws2 as worksheet

set wb = thisworkbook
set ws = wb.sheets(1)
set ws2 = wb.sheets(2)


then later in the code....


ws.cells(1,1).value = ws2.cells.value


or whatnot.

It makes it easier to read, and less likely to cause trouble if multiple workbooks are open, or if your code is interrupted and an unexpected change happens.
 
Upvote 0
BTW, always be explicit in your code If multiple sheets/workbooks are open, you can get strange results.
yes it creates problem and as you said it is good to always have explicit code.
Thank you for sharing
 
Upvote 0
can you please check & help me with this one?
 
Upvote 0

Forum statistics

Threads
1,224,732
Messages
6,180,622
Members
452,991
Latest member
JM_000888

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