使用VBA更改单个点的颜色

时间:2013-07-15 23:49:55

标签: excel excel-vba vba

我正在比较两个系列,如果第二个系列的值小于给定XValue的第一个系列,我想让第二个系列的栏变红。我尝试了一些其他的论坛答案,并得到了这个,但现在我被卡住了......

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

谢谢!

1 个答案:

答案 0 :(得分:0)

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