Extract RGB values for selected chart series

M

MikeM_work

In EXCEL 2007:
I create a pie chart using Insert > Charts.
The chart is created using the default MS Office Theme.
If I then select an individual pie slice and Format data point > the 'Fill'
is set to Automatic. When I select 'Solid fill' to try and get the RGB
values for that pie slice the color changes to a different color!

I'm trying to set up a macro to select a data series and extract the RGB
values for that data series.
The RGB values would then appear in a message box.

Thanks.

Mike
 
E

EricG

Crude, but it seems to work:

Sub Pie_Chart_Wedge_Color()
If ((ActiveChart.ChartType = xlPie Or _
ActiveChart.ChartType = xlPieExploded Or _
ActiveChart.ChartType = xlPieOfPie Or _
ActiveChart.ChartType = xl3DPie Or _
ActiveChart.ChartType = xl3DPieExploded) And _
TypeName(Selection) = "Point") Then
MsgBox "The chart you selected is: " & ActiveChart.Name & Chr(10) &
Chr(10) & _
"The wedge color is RGB(" & Selection.Fill.ForeColor.RGB Mod
256 & ", " & _
(Selection.Fill.ForeColor.RGB \
256) Mod 256 & ", " & _
(Selection.Fill.ForeColor.RGB \
256 \ 256) Mod 256 & ")"
Else
MsgBox "You must have a single wedge of a pie chart selected!"
End If
End Sub

Note that a pie chart has only one series, so you have to refer to
individual points in the series to get the color of each wedge. Select a pie
chart, then select an individual wedge in the chart, and run this routine.

HTH,

Eric
 
M

MikeM_work

Eric:
Thanks a lot; this is great!

This had been a vexing problem as we have some color blind users who need
RGB values. It's curious that it seems the only way to do this is with some
VBA. (Perhaps I'm wrong about that but I can't seem to do that simple task).

I simplified it a bit (I don't need any error trapping).
Now I can use it on any series for any chart type (or individual data point
in a pie chart):

Sub RGB_Color()

MsgBox "The chart you selected is: " & ActiveChart.Name & Chr(10) &
Chr(10) & _
"The color is RGB (" & Selection.Fill.ForeColor.RGB Mod 256 &
", " & _
(Selection.Fill.ForeColor.RGB \ 256) Mod
256 & ", " & _
(Selection.Fill.ForeColor.RGB \ 256 \ 256)
Mod 256 & ")"

End Sub

Thanks!

Mike
 

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