0

I am trying to use VBA to change font colour of data label based on cell value.

The code I use works fine with bar chart. However, It is not working with Waterfall chart. (the colour is not changed but no error pop up at all)

Below is code that I am using. Does anyone have any idea to make it work with Waterfall?

Sub tt()
    Dim i As Integer
    Dim cht As Chart
    Set cht = Sheets("sheet1").ChartObjects("Chart 3").Chart
   
    For i = 1 To 5
        On Error Resume Next
        If Sheets("Sheet1").Range("B" & i + 1).Value < 0 Then
        With cht.FullSeriesCollection(1).Points(i).DataLabel
                .Font.Color = RGB(192, 0, 0)
        End With
        Else
        With cht.FullSeriesCollection(1).Points(i).DataLabel
                .Font.Color = RGB(0, 176, 80)
        End With
        End If
    Next i
End Sub
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
PJT
  • 185
  • 1
  • 1
  • 9
  • See https://stackoverflow.com/q/71618198/4961700 – Solar Mike Mar 28 '22 at 14:11
  • 2
    Note that with `On Error Resume Next` you are not able to debug and fix your code. This line hides **all** errors (no the next one as you might think). So this makes you totally blind for any errors. You cannot see them so you cannot fix them so your code obviously cannot do what you expect it to do. – Pᴇʜ Mar 28 '22 at 14:21
  • Ahhh, thanks! now I got "Application-defined or object-defined error" with the waterfall – PJT Mar 28 '22 at 14:28
  • 1
    Well you need to tell which line. Otherwise that information is useless. – Pᴇʜ Mar 28 '22 at 14:30

0 Answers0