Greetings
I have a macro that sets the fill and/or line color of 4 different charts to either red, blue, or green.
I recorded the macro as I performed the steps that I would take and this is the code that resulted.
![]()
Private Sub Worksheet_Activate() ActiveChart.FullSeriesCollection(1).DataLabels.Select ActiveChart.FullSeriesCollection(3).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent3 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0 .Solid End With With Selection.Format.Line .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent3 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0 End With ActiveChart.FullSeriesCollection(2).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent1 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0 .Solid End With With Selection.Format.Line .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent1 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0 End With ActiveChart.FullSeriesCollection(1).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent2 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0 .Solid End With ActiveWindow.SmallScroll Down:=12 With Selection.Format.Line .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent2 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0 End With ActiveSheet.ChartObjects("Chart 1").Activate ActiveChart.FullSeriesCollection(3).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent3 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0.1499999762 .Solid End With ActiveChart.FullSeriesCollection(2).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent1 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0.1499999762 .Solid End With ActiveChart.FullSeriesCollection(1).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent2 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0.1499999762 .Solid End With ActiveSheet.ChartObjects("Chart 2").Activate ActiveChart.FullSeriesCollection(3).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent3 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0.1499999762 .Solid End With ActiveChart.FullSeriesCollection(2).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent1 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0.1499999762 .Solid End With ActiveChart.FullSeriesCollection(1).Select ActiveWindow.SmallScroll Down:=2 ActiveWindow.LargeScroll Down:=1 With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent2 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0.1499999762 .Solid End With ActiveSheet.ChartObjects("Chart 3").Activate ActiveChart.FullSeriesCollection(3).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent3 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0.1499999762 .Solid End With ActiveChart.FullSeriesCollection(2).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent1 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0.1499999762 .Solid End With ActiveChart.FullSeriesCollection(1).Select With Selection.Format.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent2 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0.1499999762 .Solid End With End Sub
But now I'm getting a Run-time error '91': Object variable or With Block variable not set.
It highlights the first line of code "ActiveChart.FullSeriesCollection(1).DataLabels.Select" when I attempt to debug.
I would really appreciate finding out what I'm missing here.
Thanks a bunch in advance.
Bookmarks