Pie Chart Colors

Q

Question Boy

I have a simple table with three columns

1. Title
2. Value
3. Color

With data like
B 8 Blue
J 5 Yellow
V 12 Green

How can I using vba set the color for each pie chart segment based on the
specified color from the respective data from the color column. So the slice
representing B (8) would be blue and the J (5) would be yellow, etc.

Thank you

QB
 
P

Peter T

Format your "color" cells with colours from the drop-down Fill color
palette. In the following change rngFirstClrCell = to suit

Sub test()
Dim n As Long
Dim cht As Chart
Dim pt As Point
Dim rFirstClrCell As Range

Set rFirstClrCell = Range("C3") ' << CHANGE

Set cht = ActiveChart
If cht Is Nothing Then
MsgBox "Select a chart"
Exit Sub
End If

For Each pt In cht.SeriesCollection(1).Points
pt.Fill.ForeColor.SchemeColor = _
rFirstClrCell.Offset(n, 0).Interior.ColorIndex
n = n + 1
Next

End Sub

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top