How can I color dots in a xy scatterplot according to column value?

后端 未结 6 941
萌比男神i
萌比男神i 2020-12-23 13:35

Consider the following worksheet:

     A       B        C        D
1 COMPANY  XVALUE   YVALUE   GROUP
2 Apple     45       35       red
3 Xerox     45                


        
6条回答
  •  臣服心动
    2020-12-23 13:54

    Recently I had to do something similar and I resolved it with the code below. Hope it helps!

    Sub ColorCode()
    Dim i As Integer
    Dim j As Integer
    i = 2
    j = 1
    
    Do While ActiveSheet.Cells(i, 1) <> ""
    
    
    If Cells(i, 5).Value = "RED" Then
    ActiveSheet.ChartObjects("YourChartName").Chart.FullSeriesCollection(1).Points(j).MarkerForegroundColor = RGB(255, 0, 0)
    
    
    
    Else
    
    If Cells(i, 5).Value = "GREEN" Then
    ActiveSheet.ChartObjects("YourChartName").Chart.FullSeriesCollection(1).Points(j).MarkerForegroundColor = RGB(0, 255, 0)
    
    Else
    
    If Cells(i, 5).Value = "GREY" Then
    ActiveSheet.ChartObjects("YourChartName").Chart.FullSeriesCollection(1).Points(j).MarkerForegroundColor = RGB(192, 192, 192)
    
    Else
    
    If Cells(i, 5).Value = "YELLOW" Then
    ActiveSheet.ChartObjects("YourChartName").Chart.FullSeriesCollection(1).Points(j).MarkerForegroundColor = RGB(255, 255, 0)
    
    End If
    End If
    End If
    End If
    
    i = i + 1
    j = j + 1
    
    Loop
    
    
    
    End Sub
    

提交回复
热议问题