Find number of graphs in a workbook

dave3009

Well-known Member
Joined
Jun 23, 2006
Messages
7,142
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. Mobile
  3. Web
Mornin' Folks

I need a wee bit of help please

How can I adjust this code I took from

http://processtrends.com/pg_chart_vba.htm

to simply count the total number of charts in a workbook. I don't need chart size and all that stuff just an integer returned with the total number

Cheers

Code:
Public Sub chart_list()
Dim chtobj As ChartObject
Dim Msg As String
Dim n As Integer
n = ActiveSheet.ChartObjects.Count
Msg = "Chart List for Sheet " & vbTab & ActiveSheet.Name & vbTab & "No charts = " & n & vbCrLf & vbCrLf
Msg = Msg & "Name " & vbTab & vbTab & "Index" & vbTab & "Top Pos" & vbTab & "Left Pos " & vbTab & "Width " & vbTab & "Height" & vbCrLf
For Each chtobj In ActiveSheet.ChartObjects
cht_width = chtobj.Width
cht_height = chtobj.Height
Top_Position = chtobj.Top
Left_Position = chtobj.Left
Msg = Msg & chtobj.Name & vbTab & vbTab & chtobj.Index & vbTab & Top_Position & vbTab & Left_Position & vbTab & cht_width & vbTab & cht_height & vbCrLf
Next chtobj
out = MsgBox(Msg, , "Chart List")
End Sub

Dave
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try

Code:
Sub countcharts()
Dim s As Worksheet, n As Integer, m As Integer
m = Charts.Count
n = 0
For Each s In Worksheets
    n = n + s.ChartObjects.Count
Next s
MsgBox m & " chart sheets" & vbCrLf & n & " embedded charts"
End Sub
 
Upvote 0
VoG II

Worked a charm, I tried it a bit later on so didn't get a chance to reply.

Genius work, Thanks

I must revisit my book, I went on a course (Non-Excel/IT related) and bought a VBA book to fill out my evenings (Didn't fancy lashing it up at the bar every night). My laptop packed in on Day 1 so never really got using the code I read about. I'll get there

Thanks for your help, I really appreciate it. Ends up the book I was presented with has 460 Charts which could easily be drafted down to 30 or so.

Cheers


Dave
 
Upvote 0

Forum statistics

Threads
1,216,103
Messages
6,128,854
Members
449,472
Latest member
ebc9

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