Private Sub CommandButton1_Click()
'PlaceTheShapeInCenterRange [c4:d8], Shapes("toto"), 5 '5%
PlaceTheShapeInCenterRange [c4], Shapes("toto"), 5 '5%
End Sub
Private Sub CommandButton2_Click()
'PlaceTheShapeInCenterRange [c11:d24], Shapes("toto"), 5 '5%
PlaceTheShapeInCenterRange [c11], Shapes("toto"), 5 '5%
End Sub
Sub PlaceTheShapeInCenterRange(rng As Range, shap, Optional marge As Long = 0) 'la marge exprime un pourcentage de 1 à x%
Dim Ratio#
Ratio = Application.Min(rng.Cells(1).MergeArea.Width / shap.Width, rng.Cells(1).MergeArea.Height / shap.Height)
With shap
.Width = .Width * (Ratio - ((Ratio / 100) * marge))
.Height = .Height * (Ratio - ((Ratio / 100) * marge))
.Top = rng.Top + ((rng.Cells(1).MergeArea.Height - .Height) / 2)
.Left = rng.Left + ((rng.Cells(1).MergeArea.Width - .Width) / 2)
End With
End Sub