Wednesday, May 18, 2011

Color Chart Series on the Basis of Series Name

If you want to set the color of series in the chart on the basis of series name. 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
        If srs.Name = "Jan" Then
            srs.Interior.Color = RGB(255, 193, 0)
        ElseIf srs.Name = "Feb" Then
            srs.Interior.Color = RGB(128, 100, 162)
        ElseIf srs.Name = "Mar" Then
            srs.Interior.Color = RGB(165, 165, 165)
        End If

End Sub

Download Working File

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...