Change color of data points in a chart in excel using VBA
HTML-код
- Опубликовано: 3 окт 2024
- 00:40 Method 1: Change data point color based on categories
06:34 Method 2: Change data point color based on numbers
Sub color_dots()
Dim s As Series
Dim i As Integer
Set s = ActiveChart.FullSeriesCollection(1)
For i = 1 To s.Points.Count
If Cells(i + 1, 3) = "A" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(255, 80, 80)
If Cells(i + 1, 3) = "B" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(255, 153, 0)
If Cells(i + 1, 3) = "C" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(0, 128, 128)
Next i
End Sub
----------------------------------------------------------------------------------------------------------------
Sub color_dots()
Dim s As Series
Dim i As Integer
Set s = ActiveChart.FullSeriesCollection(1)
For i = 1 To s.Points.Count
s.Points(i).Format.Fill.ForeColor.RGB = Cells(i + 1, 4).DisplayFormat.Interior.Color
Next i
End Sub