简体   繁体   中英

Changing colour of a single point with VBA

I'm comparing two series and if the value of the 2nd series is less than the 1st at a given XValue, I want to make the bar for that 2nd series red. I tried following some other forum answers and got to this but now I'm stuck...

Public Sub Bar_Colour()

Dim c As Chart
Dim p As Series
Dim a As Series
Dim iPoint As Long
Dim nPoint As Long

Set c = ActiveChart
Set s = ActiveChart.SeriesCollection(1)
Set a = ActiveChart.SeriesCollection(2)

nPoint = s.Points.Count

For iPoint = 1 To nPoint
    If a.Points(iPoint).Value < s.Points(iPoint).Value Then
        a.Points(iPoint).Interior.Color = RGB(255, 0, 0)
    End If
Next iPoint

End Sub

Thanks!

Public Sub Bar_Colour()

Dim c As Chart
Dim p As Series
Dim a As Series
Dim iPoint As Long
Dim nPoint As Long

Set c = ActiveChart
Set s = ActiveChart.SeriesCollection(1)
Set a = ActiveChart.SeriesCollection(2)

nPoint = s.Points.Count

For iPoint = 1 To nPoint
    If a.Values(iPoint) < s.Values(iPoint) Then
        a.Points(iPoint).Interior.Color = RGB(255, 0, 0)
    End If
Next iPoint

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM