• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Pie Colour Changes basis Legend

chirayu

Well-Known Member
Hi Guys,

I basically need consistent colours in my Pie Charts.
There are a total of 28 sites in my data set, not every pie chart created will have all 28 sites.
But each site has a specific colour value that needs to stay the same in every chart.

So when I select a chart & run the macro, it should apply the RGB to the slices for whichever sites are present in that Pie Chart basis my colour sample (attached)

I am using static YTD charts so don't need a dynamic macro that will run basis dropdown. Thanks.
 

Attachments

  • colours.xlsx
    10.9 KB · Views: 0
I basically need consistent colours in my Pie Charts.

Well, there's your problem! ;) Seriously, though, don't use a Pie Chart, especially with that many items. Should probably be using a bar chart.

Eihter way, it would help to see more how your chart's data is laid out. Your file just had the colors and key.
 
Hi Luke. Nevermind. Found myself a solution by searching on google some more. For those trying to do the same. here is the link:

http://datapigtechnologies.com/blog/index.php/color-pie-chart-slices-to-match-their-source-cells/

Also modified code to work on single chart rather than every chart in sheet

Code:
Sub ColorPies()
'http://datapigtechnologies.com/blog/index.php/color-pie-chart-slices-to-match-their-source-cells/
'Modified by Chirayu Walawalkar 19-Jun-2015
'Dim cht As ChartObject
Dim i As Integer
Dim vntValues As Variant
Dim s As String
Dim myseries As Series

  'For Each cht In ActiveSheet.ChartObjects
  With ActiveChart
  'For Each myseries In cht.Chart.SeriesCollection
  For Each myseries In ActiveChart.SeriesCollection

  If myseries.ChartType <> xlPie Then GoTo SkipNotPie
  s = Split(myseries.Formula, ",")(2)
  vntValues = myseries.Values

  For i = 1 To UBound(vntValues)
  myseries.Points(i).Interior.Color = Range(s).Cells(i).Interior.Color
  Next i
SkipNotPie:
  Next myseries
End With
  'Next cht
End Sub
 
Last edited:
Back
Top