How do you invert the color of a chart data label?
The following code is based on this one by Tim Williams and changes the label font color based on the label value:
Sub FlipLabelFontColor()
Dim k As Long
Dim j As Long
With ActiveChart
For k = 1 To .SeriesCollection.Count
For j = 1 To .SeriesCollection(k).Points.Count
With .SeriesCollection(k).Points(j).DataLabel
.Font.color = IIf(Val(.Text) < 0, vbRed, vbGreen)
End With
Next j
Next k
End With
End Sub
How do you change the color based on another color?
I’d like to invert white to black:
Sub InvertLabelFontColor()
Dim k As Long
Dim j As Long
With ActiveChart
For k = 1 To .SeriesCollection.Count
For j = 1 To .SeriesCollection(k).Points.Count
With .SeriesCollection(k).Points(j).DataLabel
' If .Font.color = RGB(255, 255, 255) Then
' .Font.color = RGB(0, 0, 0)
' End If
End With
Next j
Next k
End With
End Sub