Getting excel pie chart slices to use the colours from my data series

Big Maceo

New Member
Joined
Sep 11, 2019
Messages
4
Hi, I'm producing a pie chart in excel (2016), and each line in the data series is colour coded. I'm trying (unsuccessfully) to get excel to use the colours for each line in the data series for the corresponding pie slice in the chart, but it just uses its own default colours.

Can anybody tell me how to do it?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I wrote a tutorial about this on my blog a while back, Color Plotted Points to Match Cells.

Short answer, try this procedure, which works for pie chart, but also donut charts, column charts, and bar charts.

Code:
Sub ColorPointsToMatchCells()
  Dim srs As Series
  Dim sFmla As String
  Dim vFmla As Variant
  Dim sYvals As String
  Dim rYvals As Range
  Dim iPt As Long
  Dim nPts As Long

  If ActiveChart Is Nothing Then GoTo OuttaHere

  For Each srs In ActiveChart.SeriesCollection
    Select Case srs.ChartType
      ' only do pie, bar, column charts
      Case xlPie, xlDoughnut, xlBarClustered, xlBarStacked, xlBarStacked100, _
          xlColumnClustered, xlColumnStacked, xlColumnStacked100

        On Error GoTo SeriesError

        ' get series information
        sFmla = srs.Formula
        nPts = srs.Points.Count
        vFmla = Split(sFmla, ",")
        sYvals = vFmla(LBound(vFmla) + 2)
        Set rYvals = Range(sYvals)

        For iPt = 1 To nPts
          ' don't change point color if cell has no fill color
          If rYvals.Cells(iPt).Interior.Pattern = xlSolid Then
            srs.Points(iPt).Interior.Color = rYvals.Cells(iPt).Interior.Color
          End If
        Next
    End Select

SeriesError:
    On Error Resume Next
  Next

OuttaHere:

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top