Loop thru ChartColor

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
618
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a chart that I assigned each point within each series a specific color. However, now I would like to 'reset' the chart back to ChartColor = 10 (native series color scheme).

I can assign the ChartColor, reset the MarkerBackgroundColorIndex to clear (0), and fill the marker. This works fine for series #1, but on series number 2, I wind up with the correct marker border for series #2 (orange) but the incorrect marker interior as light blue (same as series #1).

My thought was to loop thru the ChartColor colors and assign the fill by series number but I can't find how to do this.

Any thoughts would be much appreciated. Thanks, y'all.

VBA Code:
Sub graph_autoColor()
' https://stackoverflow.com/a/21165673

Dim sht As Worksheet
  Set sht = ActiveSheet

Dim cht As ChartObject
Dim srs As series
Dim pt As Point


  For Each cht In sht.ChartObjects
    cht.Chart.ChartColor = 10  ' ~~ Possible chart color schema (10-26) || https://docs.microsoft.com/en-us/office/vba/api/Project.chart.chartcolor
 
    For Each srs In cht.Chart.SeriesCollection
      With srs
        .HasDataLabels = False
        .Format.Line.Visible = msoFalse
        .MarkerBackgroundColorIndex = 0  ' ~~ Series marker color (center fill)
[COLOR=rgb(184, 49, 47)]        .Format.Fill.Solid  ' <--- This applies the fill color for series #1 to ALL series[/COLOR]
'        .MarkerForegroundColorIndex = 0  ' ~~ Series marker line color (on outside of marker; 0 = none)
      End With
    Next srs
  Next cht

End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,748
Messages
6,126,654
Members
449,326
Latest member
asp123

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