更新图表中的点颜色

时间:2015-10-19 13:13:58

标签: excel vba excel-vba

我在Excel 2007中有一个散点图(Chart1),它引用了一个包含四列的表。我试图让图表根据D列中显示的RAG状态更新点(菱形)的颜色。例如,如果D3中的值是“On Time”,那么我想要那个特定的点(第一个是绿色等。

到目前为止我的代码如下所示,但它给出了一个编译错误:Next没有For。

Sub UpdateRAGColours()

'holds the entire data series in the chart
Dim RAGSeries As Series

'holds one cell at a time
Dim SingleCell As Range

'holds the full list of cells containing film names
Dim RAGList As Range

'keeps track of which datapoint we're labelling
Dim RAGCounter As Integer

'set the counter to start at 1
RAGCounter = 1

'set a reference to the cells containing the list of films
Set RAGList = Range("D3", "D11")

'set a reference to the chart data series
Set RAGSeries = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)

'loop over the cells in the list of films
For Each SingleCell In RAGList
Next SingleCell

'loop over the cells in the list of films
For Each SingleCell In RAGList

If Range(SingleCell) = "Complete" Then
Worksheets(6).ChartObjects(1).Chart.SeriesCollection(1).Points(RAGCounter).MarkerBackgroundColor = RGB(23, 55, 94)
 ElseIf Range(SingleCell) = "Late" Then
 Worksheets(6).ChartObjects(1).Chart.SeriesCollection(1).Points(RAGCounter).MarkerBackgroundColor = RGB(255, 0, 0)
   ElseIf Range(SingleCell) = "On Time" Then
   Worksheets(6).ChartObjects(1).Chart.SeriesCollection(1).Points(RAGCounter).MarkerBackgroundColor = RGB(0, 176, 80)
    Else: Worksheets(6).ChartObjects(1).Chart.SeriesCollection(1).Points(RAGCounter).MarkerBackgroundColor = RGB(255, 192, 0)

RAGCounter = RAGCounter + 1
Next SingleCell

ActiveSheet.ChartObjects("Chart 1").Activate

End Sub

0 个答案:

没有答案