Saturday, January 19, 2013

Color Chart Series on the Basis of Category Name

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

Sub cond_format_charts()

Dim cht As Chart

Dim srs As Series
Dim i As Long

Dim rng As Range

'change chart name here

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

' set series here

Set srs = cht.SeriesCollection(1)

    For i = 1 To srs.Points.Count

        For Each rng In Sheets("Sheet1").Range("j5:j10").Cells
            If UCase(srs.XValues(i)) = UCase(rng.Value) Then
                srs.Points(i).Interior.Color = rng.Offset(0, 2).Interior.Color
                Exit For
            End If

End Sub

No comments:

Post a Comment