Article ID: 141363
Article Last Modified on 10/11/2006
Sub SetScaleToMinAndMaxValues()
Dim ValuesArray(), SeriesValues As Variant
Dim Ctr As Integer, TotCtr As Integer
' Uses the first chart on the active worksheet.
With ActiveSheet.ChartObjects(1).Chart
' Note: Instead of the preceding line, you could use this line:
'
' With ActiveChart
'
' if you wanted to be able to run this macro on a chart sheet.
' Loops through all of the Series and retrieves the values
' and places them into an array named ValuesArray.
For Each X In .SeriesCollection
SeriesValues = X.Values
ReDim Preserve ValuesArray(1 To TotCtr + UBound(SeriesValues))
For Ctr = 1 To UBound(SeriesValues)
ValuesArray(Ctr + TotCtr) = SeriesValues(Ctr, 1)
' In Excel 97 for Windows and Excel 98 Macintosh Edition,
' change the preceding line of code to read as follows:
'
' ValuesArray(Ctr + TotCtr) = SeriesValues(Ctr)
Next
TotCtr = TotCtr + UBound(SeriesValues)
Next
' Reset the minimum and maximum scale to the minimum and
' maximum values in the ValuesArray.
.Axes(xlValue).MinimumScaleIsAuto = True
.Axes(xlValue).MaximumScaleIsAuto = True
.Axes(xlValue).MinimumScale = Application.Min(ValuesArray)
.Axes(xlValue).MaximumScale = Application.Max(ValuesArray)
End With
End Sub
Additional query words: XL
Keywords: kbdtacode kbhowto kbprogramming KB141363