I have a code in excel to change colors of bar graph but its not working. Can anyone suggest me what I am doing wrong in the code.
With ActiveChart.SeriesCollection(1).Interior.Color = RGB(0, 153, 64)
End With
This code doesnt affect color of the bar.
Also, For all bars (representing values 0 to 200) I want one color (green) but for two bars representing two data points (100 and 200), I want to add different color. Can anyone please tell me how to to that with VBA.
I would appreciate your time regarding the same.
Thanks Very much
The With statement specifies the objects or properties to be acted on. Your code should be like this:
With ActiveChart.SeriesCollection(1)
.Interior.Color = RGB(0, 153, 64)
End With
EDIT - For the 2nd part of your question:
Sub ColorBars()
Dim chtSeries As Excel.Series
Dim i As Long
For Each chtSeries In ActiveChart.SeriesCollection
With chtSeries
For i = 1 To .Points.Count
If .Values(i) = 100 Or .Values(i) = 200 Then
.Points(i).Interior.Color = .Interior.Color = RGB(75, 172, 198)
Else
.Points(i).Interior.Color = RGB(0, 153, 64)
End If
Next i
End With
Next chtSeries
End Sub