How to find all charts on a sheet

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Glaswegian

Well-known Member
Joined
Oct 14, 2003
Messages
1,487
This assumes that the charts are embedded in a worksheet and lists their names and worksheet name in column A.

Sub FindCharts()
Dim cht As ChartObject
Dim sht As Worksheet

For Each sht In ThisWorkbook.Worksheets
For Each cht In sht.ChartObjects
Sheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0).Value = cht.Name & " is on " & sht.Name
Next cht
Next sht
End Sub


HTH

Regards
 

UHsoccer

Well-known Member
Joined
Apr 3, 2002
Messages
1,023
Thanks got that to work

I am trying to set the name of each line. When I recorded a macro it looked like

ActiveChart.SeriesCollection(1).Name = "=""Gas"""

in Vb I use

ActiveChart.SeriesCollection(NumL).Name = "=" & nameProp & ""
where numL = 1 and nameProp = Gas (read from a cell)

Error is "Unable to set name property of Series class" (The chart is already on a sheet)
 

Glaswegian

Well-known Member
Joined
Oct 14, 2003
Messages
1,487
Try this

ActiveChart.SeriesCollection(NumL).Name = nameProp

You've assigned the name to the variable so no need for the extra "".

Regards
 

UHsoccer

Well-known Member
Joined
Apr 3, 2002
Messages
1,023
Thanks, I am able to write VB code, but am not to skilled using ideas like

Dim cht As ChartObject
Dim sht As Worksheet

So in general, my code is not as "elegant" and probably not as simple
 

Forum statistics

Threads
1,148,273
Messages
5,745,794
Members
423,973
Latest member
man_this_is_hard

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
Top