(Solved) – Looping though Series collection in MS Chart

(solved)-–-looping-though-series-collection-in-ms-chart

I have a chart which I would like to change the color on of its columns if the label value on the SeriesCollections DataLabels is greater than the Value
on its sister DataLabel
For example if SeriesCollection(1) with DataLabel(1) > DataLabel(2) Then .SeriesCollection(1).Points(1).Interior.Color = RGB(250, 0, 0)

I have this code which misses out some SerieCollections and also changes the color of the columns regardless of the DataLabel.Caption Value

Dim labelCaption As Currency
Dim k As Integer
Dim j As Integer
Dim c As Object
Set c = myChart.Object

With c
 For k = 1 To .SeriesCollection.Count
   For j = 1 To .SeriesCollection(k).Points.Count
   labelCaption = .SeriesCollection(k).Points(j).DataLabel.Caption
   If labelCaption > .SeriesCollection(k).Points(j).DataLabel.Caption Then
   .SeriesCollection(k).Points(j).Interior.Color = 65280
   Else
   .SeriesCollection(k).Points(j).Interior.Color = RGB(250, 0, 0)
   End If
   Next j
    
 Next k
End With

Leave a Reply

Your email address will not be published. Required fields are marked *