Re : tri ds listbox - source des donnes ds + de 2 feuilles
Bonsoir,
Les collections deviennent lentes lorsque le nb d'items devient important.
L'objet Dictionary est beaucoup + rapide.
Objet dictionary
La méthode de tri Quick Sort est également beaucoup + rapide
Sub Dictionnaire()
t = Timer
Set MonDico = CreateObject("Scripting.Dictionary")
n = 2000
For i = 1 To n
aléa = Int(Rnd * 10000)
If Not MonDico.Exists(aléa) Then MonDico.Add aléa, aléa
Next i
temp = MonDico.items
MsgBox Timer - t
Call tri(temp, LBound(temp), UBound(temp))
Application.ScreenUpdating = False
For i = LBound(temp) To UBound(temp): Cells(20 + i, 2) = temp(i): Next
End Sub
Sub tri(a, gauc, droi) ' Quick sort
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
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call tri(a, g, droi)
If gauc < d Then Call tri(a, gauc, d)
End Sub
JB