ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Charts and Charting in Excel (https://www.excelbanter.com/charts-charting-excel/)
-   -   Changing the color of a Series Collection using visual basic? (https://www.excelbanter.com/charts-charting-excel/17955-changing-color-series-collection-using-visual-basic.html)

Koreef

Changing the color of a Series Collection using visual basic?
 
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.Colo r =
3" among many others, if you could give me any help I would appreciate it.

Thanks



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.

----
Regards,
John Mansfield
http://www.pdbook.com


"Koreef" wrote:

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.Colo r =
3" among many others, if you could give me any help I would appreciate it.

Thanks




All times are GMT +1. The time now is 09:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com