Can anyone help... I wrote some code to change the plot colors in a scatter chart based on defined criteria, but I need the macro to run automatically each time the cell range is changed. Currently the macro only works if I run it manually. I am new to VBA, am I missing something in the code?
Sub ColorDot()
Dim s As Series
Dim i As Integer
Set s = ActiveChart.FullSeriesCollection(1)
For i = 1 To s.Points.Count
If Cells(i + 2, 18) = "1" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(255, 7, 1)
If Cells(i + 2, 18) = "2" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(255, 200, 0)
If Cells(i + 2, 18) = "3" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(0, 110, 230)
If Cells(i + 2, 18) = "4" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(34, 229, 1)
Next i
End Sub
Sub ColorDot()
Dim s As Series
Dim i As Integer
Set s = ActiveChart.FullSeriesCollection(1)
For i = 1 To s.Points.Count
If Cells(i + 2, 18) = "1" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(255, 7, 1)
If Cells(i + 2, 18) = "2" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(255, 200, 0)
If Cells(i + 2, 18) = "3" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(0, 110, 230)
If Cells(i + 2, 18) = "4" Then s.Points(i).Format.Fill.ForeColor.RGB = RGB(34, 229, 1)
Next i
End Sub