Conditional formatting - change color of data label in pie chart

Aviles

Board Regular
Joined
Dec 17, 2008
Messages
173
Office Version
  1. 365
Platform
  1. Windows
Hello,
I'm trying to change the color of data labels in a pie chart according to the percentage value. e.g. If =< 5%, then Black, If >5%, then White
After some research I tried entering a custom format code in the 'Number' category under 'Format Data Labels', but this didn't work: [Black][=<0.05]0%;[White][>0.05]0%
Are there any other options to accomplish what I am trying to achieve? I'm open to VBA also if it makes it easier.
Thanks.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I found this code on another thread which I think is what I'm looking for.

Could some one help me to apply this code to my pie chart please? My chart name is "Chart 26" and the data labels are "Series 3 Data Labels"

I tried to amend the code but didn't have any luck.

Thanks.

Code:
[/SIZE]Sub LabelFontColor()

    Dim ser As Series
    Dim ser_vals As Variant
    Dim num As Byte
    
    '[SIZE=3][/SIZE][SIZE=2]change[/SIZE] this line as necessary
    Set ser = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
    ser_vals = ser.Values
    
    For num = LBound(ser_vals) To UBound(ser_vals)
        With ser.Points(num).DataLabel.Format.TextFrame2.TextRange.Font.Fill.ForeColor
            If ser_vals(num) >= 0.3 Then
                .ObjectThemeColor = msoThemeColorAccent3
            Else
                .ObjectThemeColor = msoThemeColorAccent2
            End If
        End With
    Next num
    
End Sub

[SIZE=2]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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