Option Explicit
Sub GphIsoEchelles(Optional ByVal Graph As Chart = Nothing, _
Optional ByVal XGMin As Double = 0, Optional ByVal XDMin As Double = 0, _
Optional ByVal YHMin As Double = 0, Optional ByVal YBMin As Double = 0)
Dim dX As Double, dY As Double, Largeur As Double, Hauteur As Double, Ech As Double, _
ZTrac As PlotArea, ObjG As ChartObject, _
XMil As Double, YMil As Double, _
XMrg As Double, YMrg As Double, N As Long
If Graph Is Nothing Then Set Graph = ActiveChart
On Error Resume Next
With Graph
Set ZTrac = .PlotArea: Set ObjG = .Parent: If Err Then Set ObjG = Nothing
End With
On Error GoTo 0
With Graph.Axes(xlCategory): dX = .MaximumScale - .MinimumScale: End With
With Graph.Axes(xlValue): dY = .MaximumScale - .MinimumScale: End With
If ObjG Is Nothing Then
Graph.SizeWithWindow = True
ZTrac.Left = XGMin: ZTrac.Width = Graph.ChartArea.Width - XDMin - XGMin
ZTrac.Top = YHMin: ZTrac.Height = Graph.ChartArea.Height - YHMin - YBMin
End If
For N = 1 To 4
Largeur = ZTrac.InsideWidth
Hauteur = ZTrac.InsideHeight
If ObjG Is Nothing Then
Ech = ArrondiGamme(WorksheetFunction.Min(Largeur / dX, Hauteur / dY))
ZTrac.Width = ZTrac.Width - Largeur + dX * Ech
ZTrac.Height = ZTrac.Height - Hauteur + dY * Ech
Else
Ech = ArrondiGamme(Sqr((Largeur * Hauteur) / (dX * dY)))
ObjG.Width = ObjG.Width - Largeur + dX * Ech
ObjG.Height = ObjG.Height - Hauteur + dY * Ech
End If
Next N
End Sub
Function ArrondiGamme(ByVal X As Double) As Double
ArrondiGamme = 2 ^ (Int(Log(X) * 212857425 / 12295127 + 0.5) / 12)
End Function