Hi,
I'm new to here, and new to excel VBA. Could anyone help me with my problem? Thank you so much!
I'm setting up a VBA to change the bar fille color in chart.
For the VBA, I pre-set the chart series up to 5. It's work if the chart contains 5 or more series, but if the chart only contains last than 5 series, error occurred. How should I do to fix this problem?
Thank you so much for your time, and your help!
Here is my VBA:
ActiveChart.SeriesCollection(1).Select
Selection.Format.Line.Visible = msoFalse
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Solid
End With
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(246, 221, 219)
.Transparency = 0
.Solid
End With
ActiveChart.SeriesCollection(2).Select
Selection.Format.Line.Visible = msoFalse
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(246, 221, 219)
.Solid
End With
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(238, 189, 188)
.Transparency = 0
.Solid
End With
ActiveChart.SeriesCollection(3).Select
Selection.Format.Line.Visible = msoFalse
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(238, 189, 188)
.Solid
End With
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(228, 154, 152)
.Transparency = 0
.Solid
End With
ActiveChart.SeriesCollection(4).Select
Selection.Format.Line.Visible = msoFalse
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(228, 154, 152)
.Solid
End With
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(220, 120, 118)
.Transparency = 0
.Solid
End With
ActiveChart.SeriesCollection(5).Select
Selection.Format.Line.Visible = msoFalse
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(220, 120, 118)
.Solid
End With
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(208, 79, 76)
.Transparency = 0
.Solid
End With
End Sub
Bookmarks