Function XRANG(refRang As Range, ref As Range, plage As Range) As Long
Dim a, b, ncol%, x, i&, j%, v, c(), n&
a = Intersect(ref.EntireColumn, plage.EntireRow).Resize(, 2) 'matrice, plus rapide, au moins 2 éléments
b = plage
ncol = UBound(b, 2)
x = ref
For i = 1 To UBound(a)
If a(i, 1) = x Then
For j = 1 To ncol
v = b(i, j)
If IsNumeric(CStr(v)) Then
ReDim Preserve c(n)
c(n) = v
n = n + 1
End If
Next j
End If
Next i
tri c, 0, n - 1
XRANG = Application.Match(refRang, c, 0)
End Function
Sub tri(a, 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
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