Format data labels to replicate its series on a line chart

Yard

Well-known Member
Joined
Nov 5, 2008
Messages
1,929
Hi,

I have a simple Pivot line chart with half a dozen series.

On the maximum value data point on each series I have a data label showing the category name.

I want to format the data label to match the line, e.g. Series1 has a red line (from the standard Excel design/style) and I want to format my data label with a red border and red text. The same will be done to the remaining series.

I can not understand how to translate the colour properties of the line into the colour properties of the text & outline of the data label.

I have this:

Code:
Sub FormatDataLabelsLikeLine(cht As Chart)
Dim dataP As Point, dataPs As Points
Dim dataL As DataLabel
Dim Ser As Series
For Each Ser In cht.SeriesCollection
        Set dataPs = Ser.Points
        For Each dataP In dataPs
                If dataP.HasDataLabel Then
                        Set dataL = dataP.DataLabel
                        With dataL.Format.TextFrame2.TextRange.Font.Fill
                                .Visible = msoTrue
                                .ForeColor.RGB = Ser.Format.Line.ForeColor.RGB
                                .Solid
                        End With
 
                        With dataL.Format.Line
                                .Visible = msoTrue
                                .ForeColor.RGB = Ser.Format.Line.ForeColor.RGB
                        End With
                End If
        Next dataP
Next Ser
End Sub

but it changes all the datalabel text and outlines to white. Debugging it shows that it's returning the RGB value of 16777215 for

Code:
Ser.Format.Line.ForeColor.RGB

Would appreciate any guidance.

Thanks
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
bump

Anyone have any suggestions for copying standard chart style colour schemes onto other drawing objects?
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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