Reputation: 821
I have a quick question regarding modifying the axes of a ChartObject with VBA in Excel.
I have the following code, which modifies the min/max value of an axis based on the data it is charting:
Worksheets("DurationByDate").ChartObjects("DurationByDateChart").Activate
With ActiveChart.Axes(xlValue)
.MinimumScale = iDurMin - 2
.MaximumScale = iDurMax + 2
End With
This works well, but I don't like "activating" objects if I don't need to.
So I tried the following code:
With Worksheets("DurationByDate").ChartObjects("DurationByDateChart") _
.Axes(xlValue)
.MinimumScale = iDurMin - 2
.MaximumScale = iDurMax + 2
End With
This code throws an error:
Run-time Error '438': Object doesn't support this property or method
Does anyone know why it seems like the chart needs to be active in order to adjust the axes?
Upvotes: 1
Views: 325
Reputation: 14764
Add .Chart
near the end of your With
statement:
With Worksheets("DurationByDate").ChartObjects("DurationByDateChart").Chart.Axes(xlValue)
Upvotes: 2