VBA:根据系列收集自动调整所有的Y轴范围

我试图根据每个特定图表中所有系列的最大值和最小值(超过1)更新所有图表的y轴。 (因此,所有的图表将根据其中的系列进行不同的更新)。 我怎样才能做到这一点? 据我所知,没有简单的SeriesCollection(全部)选项,所以我试图使用循环。 欢迎任何更好的build议。

Public Sub UpdateChartAxes() Dim objChart As ChartObject For Each objChart In Sheets("Charts").ChartObjects UpdateChartAxis objChart Next objChart End Sub Private Sub UpdateChartAxis(ByVal objChart As ChartObject) On Error GoTo CleanFail Dim lower As Double Dim upper As Double Dim srs As Series lower = 100 upper = 0 With objChart.Chart For Each srs In .SeriesCollection If Application.RoundDown(Application.Aggregate(15, 6, srs, 1), 0) < lower _ Then lower = Application.RoundDown(Application.Aggregate(15, 6, srs, 1), 0) If Application.RoundUp(Application.Aggregate(14, 6, srs, 1), 0) > upper _ Then upper = Application.RoundUp(Application.Aggregate(14, 6, srs, 1), 0) Next srs .Axes(xlValue).MinimumScale = lower .Axes(xlValue).MaximumScale = upper End With CleanExit: Exit Sub CleanFail: Debug.Print lower Debug.Print "Failed updating axes for chart '" & objChart.Name & "'.Message: " & Err.Description Resume CleanExit End Sub 

问题是for循环中的“srs”(Aggregate不包含系列对象)。 改用“srs.Values”。