Dynamic Pie Chart Slice Fill

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,641
Office Version
  1. 365
Platform
  1. Windows
How do I change the fill of a pie slice based on the fill colour of a specified cell?

I also want to change the slice label font colour to the same font color in the same cell.

TIA
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I've found something like this in my archive.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim pieChart As Chart
   Set pieChart = ActiveSheet.ChartObjects(1).Chart
   
   Dim ser As Series
   Set ser = pieChart.SeriesCollection(1)
   
   Dim sourceRange As Range
   Set sourceRange = Application.Range(Split(ser.Formula, ",")(2))
   
   Dim n As Long
   For n = 1 To ser.Points.Count
      ser.Points(n).Interior.Color = sourceRange.Cells(n).Interior.Color
   Next
End Sub

Screenshot 2024-02-23 112647.png
 
Upvote 0
Its too late for edit.

VBA Code:
   For n = 1 To ser.Points.Count
      ser.Points(n).Interior.Color = sourceRange.Cells(n).Interior.Color
      ser.Points(n).DataLabel.Font.Color = sourceRange.Cells(n).Font.Color
   Next

second line change also font color for label on each piece of pie :-)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,984
Messages
6,175,781
Members
452,668
Latest member
mrider123

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