Hi, I am trying to format all charts on a worksheet by looping though them with VBA. The code works fine for the first chart, but doesn't change the others. the debugging line does find all nine of the charts. Can someone see the problem? Thanks!
Sub LoopThroughCharts()
Dim thissheet As Worksheet
Dim thischart As ChartObject
Set thissheet = ThisWorkbook.Sheets("mean_count_charts")
For Each thischart In thissheet.ChartObjects
With thischart.Chart
.ChartArea.Format.Line.Visible = True
.Axes(xlValue).Format.Line.Visible = msoTrue
.Axes(xlValue).MajorTickMark = xlTickMarkOutside
.Axes(xlCategory).Format.Line.Visible = msoTrue
.Axes(xlCategory).MajorTickMark = xlTickMarkInside
Debug.Print thischart.Parent.Name & vbTab & thischart.Name
End With
Next thischart
End Sub
Sub LoopThroughCharts()
Dim thissheet As Worksheet
Dim thischart As ChartObject
Set thissheet = ThisWorkbook.Sheets("mean_count_charts")
For Each thischart In thissheet.ChartObjects
With thischart.Chart
.ChartArea.Format.Line.Visible = True
.Axes(xlValue).Format.Line.Visible = msoTrue
.Axes(xlValue).MajorTickMark = xlTickMarkOutside
.Axes(xlCategory).Format.Line.Visible = msoTrue
.Axes(xlCategory).MajorTickMark = xlTickMarkInside
Debug.Print thischart.Parent.Name & vbTab & thischart.Name
End With
Next thischart
End Sub