Home > Software design >  Excel : VBA Macro to make all series in a chart the same color (RGB)
Excel : VBA Macro to make all series in a chart the same color (RGB)

Time:02-03

Reaching out to the knowledge base.

Can someone point me to an Excel Macro that would color all the series (lines) in a specific (selected/current) chart the same color?

I have started the following, but it does nothing:

  Sub Same_Color()
 Dim Chart As Chart
 Dim Series As Series

 Set Chart = ActiveChart
 Set Series = Chart.SeriesCollection(2)

 Series.Format.Line.ForeColor.RGB = RGB(0, 255, 0)

End Sub

Thanks in advance

CodePudding user response:

is it this what you need?

Sub InsertChartAndFormat()
 Dim cht As ChartObject

 Set cht = Sheet1.ChartObjects.Add(Left:=10, Width:=500, Top:=50, Height:=300)

 With cht
 .Chart.SetSourceData Source:=Sheet1.Range("A1:L2")
 .Chart.ChartType = xlBarClustered
 .Chart.SeriesCollection(1).Format.Fill.ForeColor.RGB = rgbAqua
End With

End Sub

BR Bernd

CodePudding user response:

Never Mind Solved it:

    Sub Same_Color()  Dim Chart As Chart  Dim Series As Series

 Set Chart = ActiveChart  Set Series = Chart.SeriesCollection(2)

    For Each Series In Chart.SeriesCollection
                Series.Format.Line.ForeColor.RGB = RGB(0, 255, 0)
    
    Next

End Sub

Here's one for making all the series the same thickness:

Sub Change_all_charts()

    Dim sht As Worksheet
    Dim ChtObj As ChartObject
    Dim srs As Series
    
    For Each sht In Worksheets
        For Each ChtObj In sht.ChartObjects
            For Each srs In ChtObj.Chart.SeriesCollection
                srs.Format.Line.Weight = 1
            Next
        Next
    Next
End Sub
  •  Tags:  
  • Related