2016-07-07 18 views
0

所以我想知道如何縮放圖表,以便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

如果「ActiveChart」與「圖表」不同,則寫入的代碼也不起作用。閱讀關於[With ... End With Blocks]的更多信息(https://msdn.microsoft.com/zh-cn/library/wc500chb.aspx) –

+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 
+0

這太棒了!感謝您的幫助! –