1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Sub DispatchCadeaux()
Dim m As Integer, n As Integer, i As Integer, j As Integer
Dim Res() As String
Dim Tb() As Integer
Application.ScreenUpdating = False
With Worksheets("Feuil1")
n = .Range("A1").End(xlDown).Row - 1
m = .Range("A1").End(xlToRight).Column - 1
ReDim Tb(1 To n)
For i = 1 To n
Tb(i) = i
Next i
ReDim Res(1 To n, 1 To m)
For j = 1 To m
Call AleaPermut(Res, Tb, j)
Next j
.Range("B2").Resize(n, m) = Res
End With
End Sub
Private Sub AleaPermut(ByRef Mtr, ByRef Vct, ByVal k As Integer)
Dim p As Integer, i As Integer, q As Integer
q = UBound(Mtr, 1) - k + 1
Randomize
p = Int(q * Rnd) + 1
Mtr(Vct(p), k) = "BRAVO"
For i = 1 To q - 1
Vct(i) = IIf(i < p, Vct(i), Vct(i + 1))
Next i
End Sub |