Changing the color of a Series Collection using visual basic?

K

Koreef

I am trying to change the color of a Series Collection using visual basic. I
have tried things like "Chart(1).SeriesCollection(2).Points.Interior.Color =
3" among many others, if you could give me any help I would appreciate it.

Thanks
 
J

John Mansfield

Koreef,

The examples below assume you are working with embedded charts:

To change all of the series colors for all charts in a worksheet (edit out
the markers if you don't want them):

Sub LoopSeries()
Dim ws As Worksheet
Dim ct As ChartObject
Dim ser As Series
For Each ws In Worksheets
For Each ct In ws.ChartObjects
For Each ser In ct.Chart.SeriesCollection
ser.Border.ColorIndex = 3
ser.MarkerForegroundColorIndex = 3
ser.MarkerBackgroundColorIndex = 3
Next ser
Next ct
Next ws
End Sub

If you just want to do one chart, you can activate it by clicking on it
once. Then run this:

Sub LoopSeries()
Set cht = ActiveChart
Set Srs = cht.SeriesCollection
For Each Sr In Srs
Sr.Border.ColorIndex = 3
Next Sr
End Sub

Another option that goes after the first chart in the workbook:

Sub LoopSeries()
Set cht = ActiveSheet.ChartObjects(1).Chart
Set Srs = cht.SeriesCollection
For Each Sr In Srs
Sr.Border.ColorIndex = 3
Next Sr
End Sub

Finally, use this logic to go after a named embedded chart:

Sub LoopSeries()
Set cht = ActiveSheet.ChartObjects("Chart 1")
Set Srs = cht.Chart.SeriesCollection
For Each Sr In Srs
Sr.Border.ColorIndex = 3
Next Sr
End Sub

Please post back if you are referring to chart sheets.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top