3

I’m trying to change the font color of the data labels in a Sunburst chart in Excel using VBA.

So far, I’ve tried several approaches over the past two days, but I can’t seem to access or modify the color property of the series’ data labels. For example:

ActiveChart.FullSeriesCollection(1).DataLabels.Font.Color = RGB(255, 0, 0)

This works fine for other chart types (like pie or column charts), but it doesn’t seem to have any effect on a Sunburst chart.

Has anyone managed to change the font color of Sunburst chart data labels via VBA?
Any help or workaround would be greatly appreciated.

Thanks in advance!

1 Answer 1

4

I did a little test and it looks as if the data labels of a Sunburst Chart seems to have no Font property. Instead, every single data label is a kind of a shape, and you can access the properties using Format.

Not sure if this fits your need, but for me it worked:

Dim co As ChartObject, ch As Chart, dl As DataLabel
Set co = ws.ChartObjects(1)
Set ch = co.Chart
For Each dl In ch.FullSeriesCollection(1).DataLabels
    dl.Format.TextFrame2.TextRange.Font.Size = 12
    dl.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = vbRed
    i = i + 1
Next
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your response. While trying your code, I noticed a problem. My SunburstChart is made up of many "rays". For your code to work, the data labels must be displayed on the screen and not hidden by Excel because of the small size of the radius! Otherwise I get an error code: Object required Thanks, you got me moving, however the color change doesn't work, only the font size change works.
Thanks again. I made progress thanks to your code. your code actually works. But Excel does not update the font color. When I manually go to the font properties the desired color is applied but is not displayed. Any idea? a sort of "Update Chart"
Sorry, out of ideas. For me that works, and the labels are updated immediately. You could try to use the Refresh-method of the Chart Object (eg co.Refresh), but I have to clue if this would help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.