View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
EricG EricG is offline
external usenet poster
 
Posts: 220
Default Extract RGB values for selected chart series

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

"MikeM_work" wrote:

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