Sub Tirages()
Dim dest As Range, ncol%, col%, crit$, n, a(), i&, b
Set dest = [C1]
ncol = 3
Application.ScreenUpdating = False
dest(2).Resize(Rows.Count - dest.Row, ncol).ClearContents 'RAZ
Randomize
With [Tableau1].ListObject.Range 'tableau structuré
.Sort .Columns(1), xlAscending, Header:=xlYes 'tri du tableau
For col = 1 To ncol
crit = Right(dest(1, col), 1) & "*"
n = Application.CountIf(.Columns(1), crit)
If n Then
ReDim a(1 To n)
For i = 1 To n: a(i) = Rnd: Next i 'nombres aléatoires
b = .Cells(Application.Match(crit, .Columns(1), 0), 1).Resize(n, 2) 'au moins 2 éléments
tri a, b, 1, n
dest(2, col).Resize(n) = b 'restitution
End If
Next col
End With
End Sub
Sub tri(a, b, gauc, droi) ' Quick sort
Dim ref, g, d, temp
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < a(d): d = d - 1: Loop
If g <= d Then
temp = a(g): a(g) = a(d): a(d) = temp
temp = b(g, 1): b(g, 1) = b(d, 1): b(d, 1) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call tri(a, b, g, droi)
If gauc < d Then Call tri(a, b, gauc, d)
End Sub