Pages

Wednesday, May 18, 2011

Color Chart Series On The Basis of Values

If you want to set the color of series in the chart on the basis of values. Try this code -






Sub cond_format_charts()

Dim cht As Chart

Dim srs As Series
Dim i As Long

'change chart name here

Set cht = Sheets("Sheet1").ChartObjects("Chart 3").Chart

For Each srs In cht.SeriesCollection

    For i = 1 To srs.Points.Count
        If srs.Values(i) > 10 Then
            srs.Points(i).Interior.Color = RGB(255, 193, 0)
        ElseIf srs.Values(i) >= 5 And srs.Values(i) <= 10 Then
            srs.Points(i).Interior.Color = RGB(128, 100, 162)
        ElseIf srs.Values(i) < 5 Then
            srs.Points(i).Interior.Color = RGB(165, 165, 165)
        End If
    Next
Next

End Sub



No comments:

Post a Comment