VBA Chart Project - Loop Through a FullSeriesCollecion on a Chart (Code Included)

preview_player
Показать описание
This video will show you how to Loop through the fullseriescollection. The first thing you need to do is you need to declare three objects the chartobject, the chart, and the fullseriescollection. Then we set the chart object equal to a chart with at least two series collections. A series collection is equal to an individual column of data being graphed on the chart, and the fullseriescollection contains each series or column. This is similar to the way a workbook contains individual worksheets.

Once the ChartObject is set, we activate the Chart Object, which allows us to set the Chart equal to the Active Chart within the active chart object.

Finally, we loop through each series using a For Next Loop. Within the loop, we use Msgbox to verify the loop is looping through each series.

'===================
'CODE
'===================

Sub LoopSeriesCollection()

Dim cht As ChartObject
Dim chrt As Chart
Dim fs As FullSeriesCollection

Set cht = Sheet1.ChartObjects(3)
cht.Activate

Set chrt = ActiveChart
Set FS = chrt.FullSeriesCollection
For Each itm In FS
cnt = cnt + 1
MsgBox "Currently and Item " & itm.Name
Next

End Sub
Рекомендации по теме
Комментарии
Автор

Thank you, this helped. i would avoid using the .activate. Remove
Set cht = Sheet1.ChartObjects(3)
cht.Activate


Do this:
Set chrt = Sheet1.ChartObjects(3).Chart

freeradlife