nancmadi
New Member
- Joined
- Jun 12, 2017
- Messages
- 6
Hi using Excel 2016, familiar with VBA but still a newbie..
I am 100 graphs in one sheet tab.. so I am looping two sub routines to give names to the legend & Axes Titles
I ran this code to update Legend Titles and Axes Titles... Legend and Primary Title updated fine, but I am getting
'Method 'Axes' of object _Chart Failed' and it will not update Secondary.. I recorded a macro to see if the title name was accurate and it was, can any help me understand why I am getting this run-time error?
I am 100 graphs in one sheet tab.. so I am looping two sub routines to give names to the legend & Axes Titles
I ran this code to update Legend Titles and Axes Titles... Legend and Primary Title updated fine, but I am getting
'Method 'Axes' of object _Chart Failed' and it will not update Secondary.. I recorded a macro to see if the title name was accurate and it was, can any help me understand why I am getting this run-time error?
Code:
Option Explicit
Sub UpdateYTDSeriesLegend()
Dim S As SeriesCollection
Dim A As AxisTitle
ActiveChart.SeriesCollection(1).Name = "# of FSRs"
If ActiveChart.SeriesCollection.count > 1 Then
ActiveChart.SeriesCollection(2).Name = "Cumulative % to Total"
End If
End Sub
Sub UpdateAxisTitle()
With ActiveChart
.Axes(xlValue, xlPrimary).AxisTitle.Text = "# of FSRs"
.Axes(xlValue, xlSecondary).AxisTitle.Text = "% of Total FSRs"
End With
End Sub
Sub LoopThroughCharts()
Application.ScreenUpdating = False
Dim cht As ChartObject
For Each cht In Worksheets("Defects Charts").ChartObjects
cht.Activate
Call UpdateYTDSeriesLegend
Call UpdateAxisTitle
Next cht
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: