How can I run this on every sheet? and more

shadow12345

Well-known Member
Joined
May 10, 2004
Messages
1,238
Hi,

I have the below code which does exactly what I want but I have to run it loads of times.

What I would like to do is run the below code on:
For Every sheet in the workbook. (not all have charts)
Every Chart on those sheets (max 2 per sheet)
And every series in those charts

And create one master list of all of the Series name and Values.

Can anyone help?





Code:
Sub chartcheck()

Dim txt As String, Caption As String
    Dim ChtSeries As New ChartSeries
    With ChtSeries
        'specify Chart object and series number
        .Chart = ActiveChart
        .ChartSeries = 1
        
'This gives the name of the series
Range("s2").Value = .SeriesName.Address
Range("t2").Value = .Values.Address
    End With


End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Shadow,

This is probably not exactly what you need but I think it has all the components.
Code:
Sub checkChart()
    Dim ChtSeries As New ChartSeries
    Dim iRow As Integer
    Dim iSeries As Integer
    Dim ws As Worksheet
    Dim Cht As ChartObject
    Dim masterOutput As Range
    
    Set masterOutput = Sheets("Master List").Range("A2")
    
    For Each ws In Worksheets
        For Each Cht In ws.ChartObjects
            For iSeries = 1 To Cht.Chart.SeriesCollection.Count
                With ChtSeries
                    'specify Chart object and series number
                    .Chart = Cht.Chart
                    .ChartSeries = iSeries
                    'This gives the name of the series
                    masterOutput.Offset(iRow, iSeries * 2 - 2).Value = .SeriesName
                    masterOutput.Offset(iRow, iSeries * 2 - 1).Value = .Values.Address
                End With
            Next iSeries
        iRow = iRow + 1
        Next Cht
    Next ws
End Sub

I wasn't sure how you wanted to handle the output so I had it output to a sheet called Master List starting in A2, grouping all the series per chart on the same row. Let me know if it works for you.
 
Last edited:
Upvote 0
It seems to work however is it possible to change it slighly?

I just want to adjust the output so it shows all of the values in just two cols (A and B) rather than one row per chart.

So it would be
masterOutput.Offset(iRow, iSeries * 2 - 2).Value = .SeriesName
goes in a2

masterOutput.Offset(iRow, iSeries * 2 - 1).Value = .Values.Address
Goes in b2



next chart
masterOutput.Offset(iRow, iSeries * 2 - 2).Value = .SeriesName
goes in a3

masterOutput.Offset(iRow, iSeries * 2 - 1).Value = .Values.Address
Goes in b3

And so on....
 
Upvote 0
Two things have to change the output to cells
Code:
masterOutput.Offset(iRow, 1).Value = .SeriesName
masterOutput.Offset(iRow, 2).Value = .Values.Address
and iRow assignment has to be moved inside the iSeries for loop
Code:
                End With
                iRow = iRow + 1
            Next iSeries
        Next Cht
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,480
Members
452,915
Latest member
hannnahheileen

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