TechGeek
TechGeek

Reputation: 2212

Power Point VBA - Change color of each bar

I need to change color of bar to red or green based on value. Code works fine on Column chart but does not work on waterfall chart. It says "This action is not supported."

Please help making below code waterfall chart compatible:

Sub UpdateBarColor()

    Dim p As Point
    Dim s As Series
    Dim c As Chart

    Set c = ActiveWindow.Selection.ShapeRange(1).Chart
    Set s = c.SeriesCollection(1)

    For Each p In s.Points
        Debug.Print p.Format.Fill.ForeColor.RGB
    Next

End Sub

Upvotes: 0

Views: 2069

Answers (1)

mooseman
mooseman

Reputation: 2017

This changes the bars in a waterfall chart to be gray (that's the RGB) You should be able to modify it to suit your needs

Set c = ActivePresentation.Slides(1).Shapes(1).Chart.SeriesCollection(1)

   For Each p In c.Points
        p.Format.Fill.ForeColor.RGB = RGB(169, 169, 169)
    Next

Getting xvalues from the chart, try this

Dim arr As Variant
Dim i As Integer
With ActivePresentation.Slides(1).Shapes(1).Chart.SeriesCollection(1)
arr = .XValues
For i = LBound(arr) To UBound(arr)
Debug.Print arr(i)
Next
End With

Upvotes: 2

Related Questions