I'm trying to change the value scale of a chart using VBA but I get the error "unable to set MinimumScale property of axis class". This is my first time manipulating a chart in VBA and I'm a little confused about the object classes. My charts are embedded in a worksheet and the code should scroll through each chart and change it's maximum value to the value of a cell on the worksheet. Everything works great until I get to actually assigning the values. Any advice? My code is below.
Thanks,
Dave
Thanks,
Dave
Code:
Private Sub ReScaleCharts()
Dim c As Object
Dim wksYTD As Worksheet
Dim sngMaxScale As Single
Dim sngMinScale As Single
'assign worksheet to variable
Set wksYTD = Worksheets("Rev_Exp")
'loop through charts
For Each c In wksYTD.ChartObjects
Select Case c.Name
Case "Rev_YTD"
sngMaxScale = Range("revmaxscale")
sngMinScale = 0
Case "Exp_YTD"
sngMaxScale = Range("expmaxscale")
sngMinScale = 0
Case "EBITDA_YTD"
sngMaxScale = Range("ebitmaxscale")
sngMinScale = 0
Case Else
MsgBox c.Parent.Name
End Select
'assign min and max scale values
With c.Chart.Axes(xlValue)
.MinimumScale = sngMinScale
.MaximumScale = sngMaxScale
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
Next c
End Sub