Hello,
I'm trying to write a macro to reset the primary and Secondary Y axes of all charts contained in one sheet.
The code below works fine for primary but I'm getting a run time error for the secondary.
I thought it could be because only one third of the charts have a secondary axis, so I tried to insert an if condition to test its existence (via existence of title, which isn't really the same...) but this doesn't help.
Any help would be much appreciated.
Thanks.
Julien
Sub ChangeScale()
For Each ChtObj In Sheet3.ChartObjects 'Only look at specified sheet
With ChtObj.Chart
With .Axes(xlValue)
.MaximumScale = ActiveSheet.Range("D1").Value
.MinimumScale = ActiveSheet.Range("C1").Value
.MajorUnit = ActiveSheet.Range("E1").Value
End With
If .Axes(xlValue, xlSecondary).HasTitle = True Then
With .Axes(xlValue, xlSecondary) 'or: With .Axes(2, 2)
.Select '??????
.MaximumScale = ActiveSheet.Range("D2").Value
.MinimumScale = ActiveSheet.Range("C2").Value
.MajorUnit = ActiveSheet.Range("E2").Value
End With
End If
End With
Next
End Sub
Bookmarks