Option Explicit
Dim c As Control
Sub effacer()
For Each c In Me.Controls
If c.Caption Like "*" & "Btn" & "*" Then Controls.Remove c.Name
Next
End Sub
Private Sub CommandButton1_Click()
Dim t, i, nbr, combien, depTop, depLeft, tablo(100) As Integer
Dim bouton
Call effacer
On Error Resume Next
Application.ScreenUpdating = False
combien = Application.InputBox("Combien de bouton ?", "Nombre de bouton", , Type:=1)
If combien = 0 Then Exit Sub
depTop = 20
depLeft = 20
For nbr = 1 To combien
'Faut inclure un Frame si tu le veux dans un Frame
'Set bouton = Frame1.Add("forms.CommandButton.1")
Set bouton = Controls.Add("Forms.CommandButton.1")
With bouton
For i = 0 To 100
For t = 5 To 500 Step 5
tablo(i) = t
If tablo(i) = nbr - 1 Then
depTop = depTop + 20
depLeft = depLeft - 135 '(5 x 27 = 135)
End If
.Left = depLeft + ((nbr - 1) * 27)
.Top = depTop
.Width = 27
.Height = 18
.Caption = "Btn" & nbr
Next t
Exit For
Next i
End With
Next nbr
Application.ScreenUpdating = True
End Sub