Function TriVBA(BD As Range, Mois As Range, choix)
Dim col As Variant, a, b, c(), i&
col = Application.Match(choix, Mois, 0)
If IsError(col) Then TriVBA = "": Exit Function
a = BD.Columns(col + 1)
b = BD.Columns(1)
tri a, b, 1, UBound(a)
ReDim c(1 To UBound(a), 1 To 2)
For i = 1 To UBound(a)
c(i, 1) = b(i, 1)
c(i, 2) = a(i, 1)
Next
TriVBA = c 'matrice
End Function
Sub tri(a, b, gauc, droi) ' Quick sort
Dim ref, g, d, temp
ref = a((gauc + droi) \ 2, 1)
g = gauc: d = droi
Do
Do While a(g, 1) < ref: g = g + 1: Loop
Do While ref < a(d, 1): d = d - 1: Loop
If g <= d Then
temp = a(g, 1): a(g, 1) = a(d, 1): a(d, 1) = 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