Dim t(), x As Long, i As Long, y As Long, z, a
Private Sub UserForm_Initialize()
t = Feuil1.Range("a2:n" & Feuil1.Cells(Rows.Count, 1).End(3).Row)
For i = 1 To UBound(t)
z = Cells(i + 1, Columns.Count).End(xlToLeft).Column
a = Cells(i, Columns.Count).End(xlToLeft).Column
x = x + 1
t(x, 1) = i: t(x, 2) = t(i, z): t(x, 3) = z
If a = z Then t(x - 1, 4) = i
If a <> z Then t(x, 4) = t(x, 2)
Next i
ListBox1.ColumnCount = 4
ListBox1.ColumnWidths = "40;60;25"
Call Tri(t, LBound(t), UBound(t), 2)
ListBox1.List = t
End Sub
Private Sub ListBox1_Click()
With ListBox1
If Not IsNumeric(.List(.ListIndex, 3)) Then TextBox1 = .List(.ListIndex, 3) Else TextBox1 = "": Exit Sub
End With
End Sub
Sub Tri(a, gauc, droi, colTri)
Dim ref, g, d, c, temp
ref = a((gauc + droi) \ 2, colTri)
g = gauc: d = droi
Do
Do While a(g, colTri) < ref: g = g + 1: Loop
Do While ref < a(d, colTri): d = d - 1: Loop
If g <= d Then
For c = LBound(a, 2) To UBound(a, 2)
temp = a(g, c): a(g, c) = a(d, c): a(d, c) = temp
Next
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(a, g, droi, colTri)
If gauc < d Then Call Tri(a, gauc, d, colTri)
End Sub