Try this in your button routine:
Sub ResetChartYAxis()
Dim wks As Worksheet
Dim cht As Chart
Dim rngFirstCell As Range, rngLastCell As Range, rngData As Range
Dim strFormula As String
Dim dblMin As Currency, dblMax As Currency
For Each cht In ThisWorkbook.Charts
'get first cell of source data:
strFormula = cht.SeriesCollection(1).Formula
Set rngFirstCell = Range(Split(strFormula, ",")(2))(1)
'get last cell of source data:
strFormula = cht.SeriesCollection(cht.SeriesCollection.Count).Formula
With Range(Split(strFormula, ",")(2))
Set rngLastCell = .Item(.Count)
End With
Set wks = ThisWorkbook.Worksheets(rngFirstCell.Parent.Name)
'get the variance range:
Set rngLastCell = rngLastCell.Offset(0, 1)
Set rngFirstCell = wks.Cells(rngFirstCell.Row, rngLastCell.Column)
Set rngData = wks.Range(rngFirstCell, rngLastCell)
'find min/max values:
dblMin = Application.WorksheetFunction.Min(rngData)
dblMin = Round(dblMin / 10000) * 10000
dblMax = Application.WorksheetFunction.Max(rngData)
dblMax = Round(dblMax / 10000) * 10000
'set axis to 10% over max / under min:
cht.Axes(xlValue).MinimumScale = 0.9 * dblMin
cht.Axes(xlValue).MaximumScale = 1.1 * dblMax
Next cht
End Sub
Bookmarks