Sub CentrerFormePlage(xform As Shape, xplage As Range, Optional dimension = 0)
' xform est une forme (type Shape)
' xplage est une plage de cellules (type Range)
' dimension : 1 ou "w" ou "W" ou "l" (lettre) ou "L" ou "x" ou "X" pour centrer en largeur
' : 2 ou "h" ou "H" ou "y" ou "Y" pour centrer en hauteur
' : n'importe quoi d'autre ou rien pour centrer en largeur et en hauteur
Dim oldSheet As Worksheet, Xcentre#, Ycentre#
If xplage.Areas.Count > 1 Then MsgBox "Echec centrage car la plage est multi-zones!", vbCritical: Exit Sub
If Not xplage.Parent Is xform.Parent Then MsgBox "Echec centrage car la forme et la plage ne sont pas sur la même feuille!", vbCritical: Exit Sub
Set oldSheet = ActiveSheet: xplage.Parent.Select
Xcentre = xplage.Left + xplage.Width / 2: Ycentre = xplage.Top + xplage.Height / 2
If IsMissing(dimension) Then dimension = 0
Select Case dimension
Case 1, "w", "W", "l", "L", "x", "X"
xform.Left = Xcentre - xform.Width / 2
Case 2, "h", "H", "y", "Y"
xform.Top = Ycentre - xform.Height / 2
Case Else
xform.Left = Xcentre - xform.Width / 2
xform.Top = Ycentre - xform.Height / 2
End Select
oldSheet.Select
End Sub