Dynamically fill pie chart slices - Bug in 2010?

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,632
Office Version
  1. 365
Platform
  1. Windows
I am using the following code to dynamically fill 2 slices of a pie (there will only ever be 2 slices) which has stopped working properly.

When it stopped working the first time I delete the offending chart and rebuilt it, ran the code and it worked but then on a subsequent test it stopped working properly.

When it doesn't work, it fails to fill the second slice and fills it with the same colour as the first slice.

When I step through the code, the line to select a slice select the plot area rather than the slice and when I try to select it manually it still doesn't work.

Is this a known bug in 2010? If so, is there a work around other than dynamically deleting and rebuilding the chart.


TIA
Code:
Sub SliceFill()

Dim rngFill As Range
Dim strFill As String

Dim varPointIndex

Sheets("Assignment Dashboards Charts").Select

Set rngFill = Range("ADC_SliceFills")

ActiveSheet.ChartObjects("cht_ADCPie1").Activate

Do Until rngFill = ""
   strFill = rngFill
   
   varPointIndex = Application.Match(strFill, ActiveChart.SeriesCollection(1).XValues, 0)

   If Not IsError(varPointIndex) Then
      varPointIndex = Application.Match(strFill, ActiveChart.SeriesCollection(1).XValues, 0)
      
      ActiveChart.SeriesCollection(1).Points(varPointIndex).Interior.Color = rngFill.Interior.Color
      Else
   End If

   Set rngFill = rngFill.Offset(1, 0)
Loop

Set rngFill = Range("ADC_SliceFills")

ActiveSheet.ChartObjects("cht_ADCPie2").Activate

Do Until rngFill = ""
   strFill = rngFill
   
   varPointIndex = Application.Match(strFill, ActiveChart.SeriesCollection(1).XValues, 0)

   If Not IsError(varPointIndex) Then
      varPointIndex = Application.Match(strFill, ActiveChart.SeriesCollection(1).XValues, 0)
      
      ActiveChart.SeriesCollection(1).Points(varPointIndex).Interior.Color = rngFill.Interior.Color
      Else
   End If

   Set rngFill = rngFill.Offset(1, 0)
Loop

ActiveSheet.ChartObjects("cht_ADCPie1").Activate

ActiveChart.Legend.Select

Selection.Left = 19.971
Selection.Width = 343.523

ActiveSheet.ChartObjects("cht_ADCPie2").Activate

ActiveChart.Legend.Select

Selection.Left = 19.971
Selection.Width = 343.523

Set rngFill = Nothing

End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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