Sub Bouton5_QuandClic()
Dim tablo(1 To 4, 1 To 3)
Dim c As Range
Dim i As Byte
Dim bon As Boolean
Dim nombre As Long
bon = False
i = 1
For Each c In Range('e23:e27')
If c.Text <> '' Then
tablo(i, 1) = c
tablo(i, 2) = 1
nombre = nombre + tablo(i, 2)
tablo(i, 3) = tablo(i, 2) * tablo(i, 1)
i = i + 1
End If
Next c
Do While bon <> True
retour:
For i = 1 To UBound(tablo, 1)
If tablo(i, 3) < nombre Then
nombre = nombre - tablo(i, 2)
tablo(i, 2) = tablo(i, 2) + 1
nombre = nombre + tablo(i, 2)
tablo(i, 3) = tablo(i, 2) * tablo(i, 1)
GoTo retour
Else
bon = True
End If
Next i
Loop
i = 1
For Each c In Range('e23:e27')
If c.Text <> '' Then
c.Offset(0, 2) = tablo(i, 2)
i = i + 1
End If
Next c
End Sub