View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dean Hinson[_3_] Dean Hinson[_3_] is offline
external usenet poster
 
Posts: 35
Default Programming colors on a pie chart.

Hannes,

I kind of do this for a line chart and have provided the VBA that I use
below...

Sub UpdateGraph(p_Sheet As String, p_Graph As String, p_PlotArea As String,
p_PlotSeries As String
'-----------------------------------------------------------------------------------'
' This routine will update line graph plot area dynamically and format lines
and '
' legend to pre-defined settings.

'-----------------------------------------------------------------------------------'

Dim Chart As Chart
Dim i As Integer
Dim Index As Integer

Set Chart = ThisWorkbook.Worksheets(p_Sheet).ChartObjects(p_Gr aph).Chart
Chart.SetSourceData Source:=Range(p_PlotArea), PlotBy:=xlRows

For i = 1 To Range(p_PlotSeries).Count

Select Case i
Case 1
Index = 3 'Goal - Red
Case 2
Index = 4 'Series 2 - Color
Case 3
Index = 5 'Series 3 - Color
Case 4
Index = 28 'Series 4 - Color
Case 5
Index = 7 'Series 5 - Color
Case 6
Index = 8 'Series 6 - Color
Case 7
Index = 10 'Series 7 - Color
Case 8
Index = 15 'Series 8 - Color
Case 9
Index = 17 'Series 9 - Color
Case 10
Index = 38 'Series 10 - Color
Case 11
Index = 45 'Series 11 - Color
End Select

With Chart.Legend.LegendEntries(i).LegendKey
.Border.ColorIndex = Index
.Border.Weight = xlMedium
.MarkerStyle = xlNone
End With

Next i

Set Chart = Nothing

End Sub

I think you can reference the color index on a cell pretty easily.

HTH, Dean.
"Hannes" wrote:

Hello there,

I was wondering if someone could help me do a little trick.
I have a pie-chart on one sheet and I want the colors of the pie to match
the color of a cell on a differnt sheet.

That is if cell a1 is green, I want the first slice of the pie to be green.

Is this possible?