I have a chart in Excel that I am trying to have a loop change the color of one bar in the chart and then reference a cell for the name of the exported image file. The loop runs through multiple times and in the end i get 50 charts with the same highlighted bar with 50 different names. My end goal is to change the color for one of the 50 bars in yellow, export that chart with with a name that is located in cell D3, then change all the bars back to the same color, move on to the next bar, change it to yellow and export the chart with a name that is located in cell D4.
The 50 final chart names are located in the range of D3:D53. Below is my code. Thank you very much for your help.
Dim i As Integer, n As Integer
Dim part1 As String
For i = 1 To 50
For n = 3 To 52
part1 = Cells(n, 4)
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Points(i).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 255, 0)
.Transparency = 0
.Solid
End With
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Export "ImageSaveLocation" & part1 & ".png"
ActiveChart.SeriesCollection(1).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 112, 192)
.Transparency = 0
.Solid
End With
Next n
Next i
End Sub