Colouring segments of pie chart using value

anna82marie

New Member
Joined
Jan 22, 2014
Messages
15
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I've created a pie chart (it has to be a pie chart unfortunately), with data labels and values.
I need a code to automatically colour the segments red, amber or green, according to the value; 1-2 green, 3-4 amber and 5 red.
So far I have this, but it's analysing the category instead of the value; how do I change it?
Sub Pie_Colour()

Sheets("Dashboard").Select
ActiveSheet.ChartObjects("Chart 27").Activate
ActiveChart.PlotArea.Select

Dim i As Long
Dim PointText As String
With ActiveChart.SeriesCollection(1)
For i = 1 To .Points.Count
With .Points(i)
.ApplyDataLabels Type:= _
xlDataLabelsShowLabel, AutoText:=True
ValueText = .DataLabel.Text
Select Case ValueText

Case "5"
.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
Case "4"
.Format.Fill.ForeColor.RGB = RGB(255, 255, 0)
Case "3"
.Format.Fill.ForeColor.RGB = RGB(255, 255, 0)
Case "2"
.Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
Case "1"
.Format.Fill.ForeColor.RGB = RGB(0, 255, 0)

End Select
.HasDataLabel = False
End With
Next i
End With

End Sub


Please help; I've got a deadline to meet by Thursday morning!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,225,213
Messages
6,183,620
Members
453,176
Latest member
alphonsa12

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