Changing the labelcolor in a chart based on source text color

Rhalecki

New Member
Joined
Mar 5, 2013
Messages
18
I have data. 2 columns a2:b5

each row has a different font color


apple 4
banana 3
peach 2
pear 1

I want the label in a chart to march the font color of the source cell

So in a chart I'd have 4 labels:
"apple"
"banana"
"peach"
"pear"

I can't see how to do it. When i select the albels it's "all or none". I can change ll the labels to a color. But, I want each individual label to be a diferent color.

I suspect the answer is in VBA, but I'm not quite sure how to go about it.

Thanks
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
If you mean data labels (not axis labels), then this is doable. Make a column chart of your data, add labels, and then go to the "Developer" tab and click "record macro". Click the labels once, and then a single label one more time after a short pause. You should only have 1 out of 4 labels selected. Then you can change the color of that label, and click "stop recording". This should give you some code like this (sorry, Japanese excel):

Code:
    ActiveSheet.ChartObjects("グラフ 1").Activate
    ActiveChart.SeriesCollection(1).DataLabels.Select
    ActiveChart.SeriesCollection(1).Points(1).DataLabel.Select
    With Selection.Format.TextFrame2.TextRange.Font.Fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(255, 0, 0)
        .Transparency = 0
        .Solid
    End With

So you can select a single label by using:

Code:
SeriesCollection(1).Points(1).DataLabel.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0)

You can loop through the various points by using a for loop, and you can get the specific RGB color from a cell by using VBA to look that up.

I don't know how familiar you are with VBA, and what your actual data/chart object are like, so I won't write the code to do it, but that should get you started if you want to learn yourself.
 
Upvote 0
Sal,
This is helpful. But, I realize now that I want to change the axis labels. Is there anyway to do that?
Rich
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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