Sub MiseEchelle()
Dim z As Byte, nbgraph As Byte 'à moins qu'il y en ait plus de 255 !
nbgraph = Sheets(3).ChartObjects.Count
For z = 1 To nbgraph 'pourquoi boucler à l'envers ?!
Echelle Sheets(3), "Graphique " & z, "abs" & z, "ord" & z
Next z
End Sub
Sub Echelle(ws As Worksheet, Graph$, abscisses$, ordonnees$)
Dim Min#, Max#
With ws.ChartObjects(Graph).Chart
Min = Application.Min(Range(ordonnees))
Max = Application.Max(Range(ordonnees))
If Min < 0 Then
Min = Application.RoundUp(Min, 2)
Else
Min = Application.RoundDown(Min, 2)
End If
Max = Application.RoundUp(Max, 2)
With .Axes(xlValue)
.CrossesAt = Min
.MinimumScale = Min
.MaximumScale = Max
.MajorUnit = (Max - Min) / 4
End With
Min = Application.Min(Range(abscisses))
Max = Application.Max(Range(abscisses))
If Min < 0 Then
Min = Application.RoundUp(Min, 2)
Else
Min = Application.RoundDown(Min, 2)
End If
Max = Application.RoundUp(Max, 2)
With .Axes(xlCategory)
.CrossesAt = Min
.MinimumScale = Min
.MaximumScale = Max
.MajorUnit = (Max - Min) / 4
End With
End With
End Sub