Sub TriTableau2DIndexé()
'tt = Timer()
Dim clé(), index() As Long
a = [A2:J20000].Value
tt = Timer()
Dim b()
ReDim b(LBound(a) To UBound(a), LBound(a, 2) To UBound(a, 2))
ReDim clé(LBound(a) To UBound(a, 1))
ReDim index(LBound(a) To UBound(a, 1))
For i = LBound(a) To UBound(a, 1)
clé(i) = a(i, 4): index(i) = i
Next i
Call Tri(clé(), index(), LBound(a), UBound(clé))
For lig = LBound(clé) To UBound(clé)
For col = LBound(a, 2) To UBound(a, 2): b(lig, col) = a(index(lig), col): Next col
Next lig
MsgBox Timer() - tt
[P2].Resize(UBound(b), UBound(b, 2)).Value2 = b ' Tableau trié dans le tableur
End Sub
Sub Tri(clé(), index() As Long, gauc, droi) ' Quick sort
ref = clé((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While clé(g) < ref: g = g + 1: Loop
Do While ref < clé(d): d = d - 1: Loop
If g <= d Then
temp = clé(g): clé(g) = clé(d): clé(d) = temp
temp = index(g): index(g) = index(d): index(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(clé, index, g, droi)
If gauc < d Then Call Tri(clé, index, gauc, d)
End Sub