Function NbrEquipe(plage As Range, couleur As String, ratio As Long, methode As String)
Dim t, ech As Boolean, j&, i&, aux, total, somme, nbr&
t = plage
If methode = "+" Then
Do
ech = False
For i = 1 To UBound(t) - 1
If t(i, 3) < t(i + 1, 3) Then
For j = 1 To 3: aux = t(i, j): t(i, j) = t(i + 1, j): t(i + 1, j) = aux: ech = True: Next j
End If
Next i
Loop Until ech = False
ElseIf methode = "-" Then
Do
ech = False
For i = 1 To UBound(t) - 1
If t(i, 3) > t(i + 1, 3) Then
For j = 1 To 3: aux = t(i, j): t(i, j) = t(i + 1, j): t(i + 1, j) = aux: ech = True: Next j
End If
Next i
Loop Until ech = False
End If
For i = 1 To UBound(t): total = total + IIf(Trim(t(i, 1)) = Trim(couleur), t(i, 3), 0): Next
For i = 1 To UBound(t)
If Trim(t(i, 1)) = Trim(couleur) Then
somme = somme + t(i, 3)
nbr = nbr + 1
If (somme / total) >= ratio / 100 Then NbrEquipe = nbr: Exit Function
End If
Next i
End Function