title: Format slice of Excel pie chart based on Horizontal category axis
body: <p>I am looking for a way to format the colour of the slices in a pie chart, based on the values of the horizontal category axis.</p>
  <p>For example, I have a pie chart with the following data labels (which are sourced from the category axis labels):</p>
  <ul>
  <li>Apples</li>
  <li>Bananas</li>
  <li>Oranges</li>
  <li>Grapes</li>
  </ul>
  <p>The totals of each fruit add up to 100%.</p>
  <p>In the pie chart, the slice representing Apples for instance is always coloured GREEN.  Bananas is always YELLOW, and so on.  Each month I have to update the pie chart, and each month the values of Apples, Bananas, Oranges and Grapes changes.  However, the slice colours do not change.</p>
  <p>My question is - is there a way to update the pie chart every month and keep the colours associated with each type of fruit?  Also keeping in mind, some months may have additional fruits, and some months may omit some fruits.</p>
  <p>I have tried changing it according to each slice's <code>Points(x)</code> value, but because the number of series may change from month to month, it wouldn't work.  As you can see from the below, I've managed to change it according to each slice's <code>Points(x)</code> value, but am wondering if I could include an IF loop to say something like... <code>IF category axis = &quot;Apples&quot;, Selection.Format.Fill ... (fill slice with RGB(X, X, X))</code> etc.</p>
  <pre><code>Sub test()
  
      ActiveChart.SeriesCollection(1).Select
      ActiveChart.SeriesCollection(1).Points(2).Select
      With Selection.Format.Fill
          .Visible = msoTrue
          .ForeColor.RGB = RGB(255, 144, 44)
          .Transparency = 0
          .Solid
      End With
      ActiveChart.SeriesCollection(1).Points(3).Select
      With Selection.Format.Fill
          .Visible = msoTrue
          .ForeColor.RGB = RGB(112, 48, 30)
          .Transparency = 0
          .Solid
      End With
          ActiveChart.SeriesCollection(1).Points(6).Select
      With Selection.Format.Fill
          .Visible = msoTrue
          .ForeColor.RGB = RGB(112, 48, 160)
          .Transparency = 0
          .Solid
      End With
  End Sub
  </code></pre>
  <p>If anyone could assist I'd be very grateful.</p>