在VBA中是否可以找到系列集合中的最后一个值?

问题描述 投票:0回答:1
Sub Series_Values()

Dim Cht As Chart

For Each Cht In ActiveWorkbook.Charts

    
    For i = 1 To Cht.SeriesCollection.Count
        Debug.Print Cht.SeriesCollection(i).Name
        Debug.Print WorksheetFunction.Max(Cht.SeriesCollection(i).Values)
        Debug.Print Cht.SeriesCollection(i).Points.Count
        Debug.Print Cht.SeriesCollection(i).Values(Points.Count)
    Next i

Next Cht

End Sub

就我而言,最大值通常是正确的答案。但我更愿意找到该系列中的最后一个 Y 值。 Values(Points.Count) 代码将不起作用。

excel vba
1个回答
0
投票
  • 您的代码很接近。将
    .Value
    赋值给数组,然后检索最后一项。
Sub Series_Values()
    Dim Cht As Chart, i As Long, aVal
    For Each Cht In ActiveWorkbook.Charts
        For i = 1 To Cht.SeriesCollection.Count
            With Cht.SeriesCollection(i)
                Debug.Print .Name
                Debug.Print WorksheetFunction.Max(.Values)
                Debug.Print .Points.Count
                aVal = .Values
                Debug.Print aVal(UBound(aVal)) ' last point
                ' OR
                Debug.Print aVal(.Points.Count) ' last point
            End With
        Next i
    Next Cht
End Sub

© www.soinside.com 2019 - 2024. All rights reserved.