change series color with vba

  • Thread starter Thread starter barry
  • Start date Start date
B

barry

Chart consists of 2 D line type with 2 series. I run a
vba code which changes a nunber of the features.

I am stuck with changing the color of the line for the
seperate series.

tia

Barry
 
Hi

The following sets series 1 to blue, series 2 to green.
check out the colorindex palette in help to see the colors tha
correspond to the colorindex numbers:

sub set_series_colors()
ActiveChart.SeriesCollection(1).ColorIndex = 25
ActiveChart.SeriesCollection(2).ColorIndex = 4
end su
 
Nicky -

The series itself has no colorindex property. For a line or scatter
chart, you have three colors to set:

Sub set_series_colors()
ActiveChart.SeriesCollection(1).MarkerForegroundColorIndex = 25
ActiveChart.SeriesCollection(1).MarkerBackgroundColorIndex = 25
ActiveChart.SeriesCollection(1).Border.ColorIndex = 25
ActiveChart.SeriesCollection(2).MarkerForegroundColorIndex = 4
ActiveChart.SeriesCollection(2).MarkerBackgroundColorIndex = 4
ActiveChart.SeriesCollection(2).Border.ColorIndex = 4
End Sub

For chart types with a fill (area, column, bar, etc), there are only two:

Sub set_series_colors()
ActiveChart.SeriesCollection(1).Interior.ColorIndex = 25
ActiveChart.SeriesCollection(1).Border.ColorIndex = 25
ActiveChart.SeriesCollection(2).Interior.ColorIndex = 4
ActiveChart.SeriesCollection(2).Border.ColorIndex = 4
End Sub

The easiest way to figure these out, in fact the way I did it myself, is
to turn on the macro recorder and see what it spits out.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
Back
Top