我正在尝试根据不同于 X 或 Y 的值更改散点图中的标记颜色。该值与标记的 X 和 Y 在同一行中。我已经这样做了,但我似乎无法正确定义值区域。我并没有真正编码,所以我可能会以错误的方式看待它......
Sub color_chart()
Dim chartIterator As Integer, pointIterator As Integer, _
seriesArray() As Variant
For chartIterator = 1 To ActiveSheet.ChartObjects.Count
seriesArray = ActiveWorkbook.Sheets("Graph").ChartObjects(chartIterator). _
Chart.SeriesCollection(1).Values
For pointIterator = 1 To UBound(seriesArray)
Dim value As Range
Set value = Worksheets("Ranking").Range("F6", "F11")
Dim valueR As Integer
Set valueR = value.Cells.Item(1, pointIterator)
If valueR(pointIterator) = 0 Then
ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(255, 0, 0)
ElseIf valueR(pointIterator) = 1 Then
ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(255, 102, 102)
ElseIf valueR(pointIterator) = 2 Then
ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(255, 128, 0)
ElseIf valueR(pointIterator) = 3 Then
ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(255, 255, 0)
ElseIf valueR(pointIterator) = 4 Then
ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(128, 255, 0)
ElseIf valueR(pointIterator) = 5 Then
ActiveWorkbook.Sheets("Sheet1").ChartObjects(chartIterator). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(0, 255, 0)
End If
Next pointIterator
Next chartIterator
End Sub