align 0 on both axis excel code example
Example: align 0 on both axis excel
' Helper Macros
Sub AlignY_PrimaryMinimum()
AlignY 1
End Sub
Sub AlignY_PrimaryMaximum()
AlignY 2
End Sub
Sub AlignY_SecondaryMinimum()
AlignY 3
End Sub
Sub AlignY_SecondaryMaximum()
AlignY 4
End Sub
' The Main Event
Sub AlignY(FreeParam As Integer)
'' FreeParam: AXIS ALLOWED TO VARY
'' 1: Y1 (PRI) MIN
'' 2: Y1 (PRI) MAX
'' 3: Y2 (SEC) MIN
'' 4: Y2 (SEC) MAX
Dim Y1min As Double
Dim Y1max As Double
Dim Y2min As Double
Dim Y2max As Double
With ActiveChart
With .Axes(2, 1)
Y1min = .MinimumScale
Y1max = .MaximumScale
.MinimumScaleIsAuto = False
.MaximumScaleIsAuto = False
End With
With .Axes(2, 2)
Y2min = .MinimumScale
Y2max = .MaximumScale
.MinimumScaleIsAuto = False
.MaximumScaleIsAuto = False
End With
Select Case FreeParam
Case 1
If Y2max <> 0 Then _
.Axes(2, 1).MinimumScale = Y2min * Y1max / Y2max
Case 2
If Y2min <> 0 Then _
.Axes(2, 1).MaximumScale = Y1min * Y2max / Y2min
Case 3
If Y1max <> 0 Then _
.Axes(2, 2).MinimumScale = Y1min * Y2max / Y1max
Case 4
If Y1min <> 0 Then _
.Axes(2, 2).MaximumScale = Y2min * Y1max / Y1min
End Select
End With
End Sub