I have an Excel sheet with some data and a graph. I use the following code, setting the minimum and maximum value for the Value (Y) axis. This works fine:
Dim cht As ChartObject
MaxChartNumber = Application.WorksheetFunction.RoundUp(totalWeights(1, 1), 0)
MinChartNumber = totalWeights(daysToPip, 8)
If totalWeights(daysToPip, 9) < MinChartNumber Then
MinChartNumber = totalWeights(daysToPip, 9)
End If
MinChartNumber = Application.WorksheetFunction.RoundDown(MinChartNumber, 0)
For Each cht In ActiveSheet.ChartObjects
cht.Chart.Axes(xlValue).MinimumScale = MinChartNumber
cht.Chart.Axes(xlValue).MaximumScale = MaxChartNumber
Next cht
I would like to have a minimum and maximum for the Category (X) as well. So I added:
For Each cht In ActiveSheet.ChartObjects
cht.Chart.Axes(xlValue).MinimumScale = MinChartNumber
cht.Chart.Axes(xlValue).MaximumScale = MaxChartNumber
cht.Chart.Axes(xlCategory).MinimumScale = 1
cht.Chart.Axes(xlCategory).MaximumScale = daysToPip
Next cht
This throws an error:
What is the correct procedure to do this?