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