Excel 2013 Chart Series ForeColor.RGB Ideas (VBA) - Array?

bs0d

Well-known Member
Joined
Dec 29, 2006
Messages
622
I have a chart that when a new series is added, Excel automatically choses the color. I've learned it colors the series according to the Theme -->Colors --> Accents 1-6. I don't particularly like the default colors it's using in the chart for display/contrast purposes. Instead, I'd like to use VBA to pick from a pre-defined list of colors at random. For instance, an array of 10 colors and randomly select color from the array. I wanted to get some ideas on different ways to achieve this.

Note - I could just change the 6 theme accent colors to something more desirable, but it is a global change affecting other parts of the workbook, where I'd like these colors to apply to the chart only.

Here is the chart series code to apply a color using RBG
Code:
ActiveChart.FullSeriesCollection(ChartSeriesValue).Select
                With Selection.Format.Line
                    .Visible = msoTrue
                    'fixed color:
                    .ForeColor.RGB = RGB(255, 0, 0) 'comment out and Excel will cycle through 6 accent colors
                    .Transparency = 0
                    .Weight = 1
                End With

I could also randomize the color like this, but I think relying on a random color may be too risky for this project:
Code:
.ForeColor.RGB = RGB(Round((255 - 0) * Rnd + 0, 0), Round((255 - 0) * Rnd + 0, 0), Round((255 - 0) * Rnd + 0, 0))

an alternate code to change the color using msoThemeColor:

Code:
.ForeColor.ObjectThemeColor = msoThemeColorText1    'black
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Have you tried using the ForeColor's SchemeColor property? I think the SchemeColor is ColorIndex + 7. So red would be:

Code:
ActiveChart.SeriesCollection(1).Format.Line.ForeColor.SchemeColor = 10
 
Upvote 0
Have you tried using the ForeColor's SchemeColor property? I think the SchemeColor is ColorIndex + 7. So red would be:

Code:
ActiveChart.SeriesCollection(1).Format.Line.ForeColor.SchemeColor = 10

Ok, so maybe something like this:

Code:
'Ten chart colors:
chartColors = Array(10, 12, 14, 16, 18, 20, 22, 24, 26, 28)
Num = Application.WorksheetFunction.RandBetween(LBound(chartColors), UBound(chartColors))
ActiveChart.SeriesCollection(1).Format.Line.ForeColor.SchemeColor = Num
 
Upvote 0
That would give you a SchemeColor between 1 and 10. This seems to work:

Rich (BB code):
Num = ChartColors(Application.RandBetween(LBound(ChartColors), UBound(ChartColors)))
 
Upvote 0
I see, thanks for the feedback. I think this is a good approach to get where I want.
 
Upvote 0

Forum statistics

Threads
1,215,527
Messages
6,125,333
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top