I’m trying to get the minimum and maximum values for the displayed chart series in a particular range of X and Y axes (see attached figure). I’ve found a code that does that for the whole series range (see below), but I’m only interested in getting the min/max series values for any particular range, that is, for a subset of the whole series range. Can anyone help me modify the code below to achieve this task?
Sub GetSeriesMinAndMaxValues()
Dim ValuesArray(), SeriesValues As Variant
Dim Ctr As Integer, TotCtr As Integer
Dim X As Series, i As Integer
Dim Xmin As Double, Xmax As Double, Ymin As Double, Ymax As Double
TotCtr = 0
With ActiveSheet.ChartObjects(“TemperatureChart”).Chart
‘ Loops through all of the Series and retrieves the values
‘ and places them into an array named ValuesArray.
For i = 1 To 2
For Each X In .SeriesCollection
If i = 1 Then SeriesValues = X.Values
If i = 2 Then SeriesValues = X.XValues
ReDim Preserve ValuesArray(1 To TotCtr + UBound(SeriesValues))
For Ctr = 1 To UBound(SeriesValues)
ValuesArray(Ctr + TotCtr) = SeriesValues(Ctr)
Next Ctr
TotCtr = TotCtr + UBound(SeriesValues)
Next
If i = 1 Then
Ymin = Application.Min(ValuesArray)
Ymax = Application.Max(ValuesArray)
Else
Xmin = Application.Min(ValuesArray)
Xmax = Application.Max(ValuesArray)
End If
TotCtr = 0
Next i
End With
Range(“F7”) = Xmin
Range(“F8”) = Xmax
Range(“G7”) = Ymin
Range(“G8”) = Ymax
End Sub