I would like to be able to control the color of the sections in a pie chart programmically. Ideally my chart would be based on a 3-column table with the columns being: The Data Value, The Label, and the Pie Chart Color Value. The color values would be that same numbers one sees in Access form properties.
Thanks,
Steve
Sub a()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Points.Item(1).Interior.ColorIndex = 7
End Sub
You can learn the color represented by ColorIndex with the trick I posted in This Other Answer
Perhaps something on these lines?
Dim ws As Worksheet
Dim sh As Shape
Set ws = Sheet2
Set sh = ws.Shapes.AddChart '.Select
With sh.Chart
.ChartType = xlPie
.SetSourceData Source:=Range("Sheet1!$A$1:$B$3")
For i = 1 To .SeriesCollection(1).Points.Count
With .SeriesCollection(1).Points(i).Format.Fill
.ForeColor.RGB = Range("C" & i).Interior.Color
.Solid
End With
Next
End With
This will allow you to add a colour to a cell using the fill button and have it used for a segment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With