pie chart colors same as data inside pivot table chart

jordanburch

Active Member
Joined
Jun 10, 2016
Messages
443
Office Version
  1. 2016
Hey Guys,

I thought this would be easier since its a logical process. I am wanting to make the rows the same color as the data on the pie chart. These are very simple pie charts and each row has a slice of the pie. Is there an easy way to make the pie chart colors auto match the rows on the pivot table?
Thanks,

Jordan
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Here is a copy of my code. It includes a couple of test routines:
Code:
Option Explicit
Sub ColorPies(strColorSource As String)
Dim cht As ChartObject
Dim sh As Object
Dim i As Integer
Dim vntValues As Variant
Dim s As String
Dim MySeries As Series
'
'
For Each sh In ActiveWorkbook.Sheets
    sh.Activate
    If TypeName(ActiveSheet) = "Chart" Then
        For Each MySeries In ActiveChart.SeriesCollection
            If MySeries.ChartType = xlPie _
                Or MySeries.ChartType = xl3DPie _
                Or MySeries.ChartType = xlPieExploded _
                Or MySeries.ChartType = xl3DPieExploded _
            Then
                If LCase(strColorSource) = "values" Then
                    ' VALUES have the color code:
                    s = Split(MySeries.Formula, ",")(2)
                    vntValues = MySeries.Values
                Else
                    ' LABELS have the color code:
                    s = Split(MySeries.Formula, ",")(1)
                    vntValues = MySeries.XValues
                End If
                ' for both:
                For i = 1 To UBound(vntValues)
                    MySeries.Points(i).Interior.Color = Range(s).Cells(i).Interior.Color
                Next i
                '
            End If
        Next MySeries
    Else
        For Each cht In ActiveSheet.ChartObjects
            For Each MySeries In cht.Chart.SeriesCollection
                If MySeries.ChartType = xlPie _
                    Or MySeries.ChartType = xl3DPie _
                    Or MySeries.ChartType = xlPieExploded _
                    Or MySeries.ChartType = xl3DPieExploded _
                Then
                If LCase(strColorSource) = "values" Then
                    ' VALUES have the color code:
                    s = Split(MySeries.Formula, ",")(2)
                    vntValues = MySeries.Values
                Else
                    ' LABELS have the color code:
                    s = Split(MySeries.Formula, ",")(1)
                    vntValues = MySeries.XValues
                End If
                ' for both:
                For i = 1 To UBound(vntValues)
                    MySeries.Points(i).Interior.Color = Range(s).Cells(i).Interior.Color
                Next i
                '
                End If
            Next MySeries
        Next cht
    End If
Next sh
    Set cht = Nothing
End Sub
Sub UseColorFromValues()
    ColorPies ("Values")
End Sub
Sub UseColorFromLabels()
    ColorPies ("Labels")
End Sub
You can use the colours in either the values or the headings.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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