S
Sandres
Guest
Bonjour
----------
Sub RandomPlage(Plage As Range, Optional Max As Long = 0)
Dim Arr(), ArrTmp, temp, idx As Long, i As Long, j&
Randomize
ArrTmp = Plage.Value
'Tri aléatoire du tableau
For i = Plage.Rows.Count To 1 Step -1
idx = Int(Rnd() * i) + 1
temp = ArrTmp(i, 1)
ArrTmp(i, 1) = ArrTmp(idx, 1)
ArrTmp(idx, 1) = temp
j = Plage.Rows.Count - i
If Max > 0 And j = Max Then Exit For
ReDim Preserve Arr(j)
Arr(j) = ArrTmp(i, 1)
Next i
Plage.Range("e1:e" & UBound(Arr) + 1).Value = _
Application.Transpose(Arr)
End Sub 'fs
'exemple
'pour renvoyer en E1:e20 les 20 premières valeurs, après tri, de la
'plage A1:A53 :
'--------------------------------
Sub test()
Do Until g22 = 7
RandomPlage Range("A1:A53"), 20
Loop
'Recuperer les valeurs calculées
Range("B42:e42").Copy
Range("B" & ligne + 46).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
For rangee = 6 To 25
With Cells(ligne + 46, rangee)
.Value = Cells(rangee - 5, 5)
End With
Next rangee
End Sub
------------------------------------------------------
SAndres
----------
Sub RandomPlage(Plage As Range, Optional Max As Long = 0)
Dim Arr(), ArrTmp, temp, idx As Long, i As Long, j&
Randomize
ArrTmp = Plage.Value
'Tri aléatoire du tableau
For i = Plage.Rows.Count To 1 Step -1
idx = Int(Rnd() * i) + 1
temp = ArrTmp(i, 1)
ArrTmp(i, 1) = ArrTmp(idx, 1)
ArrTmp(idx, 1) = temp
j = Plage.Rows.Count - i
If Max > 0 And j = Max Then Exit For
ReDim Preserve Arr(j)
Arr(j) = ArrTmp(i, 1)
Next i
Plage.Range("e1:e" & UBound(Arr) + 1).Value = _
Application.Transpose(Arr)
End Sub 'fs
'exemple
'pour renvoyer en E1:e20 les 20 premières valeurs, après tri, de la
'plage A1:A53 :
'--------------------------------
Sub test()
Do Until g22 = 7
RandomPlage Range("A1:A53"), 20
Loop
'Recuperer les valeurs calculées
Range("B42:e42").Copy
Range("B" & ligne + 46).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
For rangee = 6 To 25
With Cells(ligne + 46, rangee)
.Value = Cells(rangee - 5, 5)
End With
Next rangee
End Sub
------------------------------------------------------
SAndres