我有一个包含许多系列的图表。并且我想要将图表中的所有条形图(所有系列)用红色(如果它具有值<100)和绿色(如果它具有值>> 100)。我的代码是
Private Sub CommandButton1_Click()
Dim chartIterator As Integer, pointIterator As Integer, seriescollectionIterator As Integer, _
seriesArray() As Variant
For chartIterator = 1 To ActiveSheet.ChartObjects.Count
For seriescollectionIterator = 1 To ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator).Chart.SeriesCollection.Count
seriesArray = ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator).Chart.SeriesCollection(seriescollectionIterator).Values
For pointIterator = 1 To UBound(seriesArray)
If seriesArray(pointIterator) >= 5 Then
ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(146, 208, 80)
Else
ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(255, 0, 0)
End If
Next pointIterator
Next seriescollectionIterator
Next chartIterator
End Sub
问题是这仅适用于第一个系列。我调试了。虽然seriescollectionIterator更新,但没有任何反应。请帮我纠正这个错误。
答案 0 :(得分:1)
中间部分专指SeriesCollection(1)
- 您需要:
If seriesArray(pointIterator) >= 5 Then
ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator). _
Chart.SeriesCollection(seriescollectionIterator).Points(pointIterator).Interior.Color = _
RGB(146, 208, 80)
Else
ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator). _
Chart.SeriesCollection(seriescollectionIterator).Points(pointIterator).Interior.Color = _
RGB(255, 0, 0)
End If