查找活动图表的最小值

时间:2016-07-07 19:56:26

标签: excel vba

所以我想知道如何缩放图表,以便y轴的最小值成为图表上所有系列之间的最小值。这是我正在使用的代码:

 Sub This()

    With Sheets("Plots").ChartObjects("The Chart").Chart.Axes(xlValue)
        For i = ActiveChart.SeriesCollection.Count To 1 Step -1
          **find minimum value**
        Next i
     .MinimumScale = miny         
    End With
End Sub 

1 个答案:

答案 0 :(得分:4)

Sub Tester()

    Dim cht As Chart
    Dim s As Series, mins(), x

    Set cht = Sheets("Plots").ChartObjects("The Chart").Chart

    ReDim mins(1 To cht.SeriesCollection.Count)
    x = 1

    For Each s In cht.SeriesCollection
        mins(x) = Application.Min(s.Values)
        x = x + 1
    Next s

    cht.Axes(xlValue).MinimumScale = Application.Min(mins)

End Sub