Function perso_mediane(ByVal col_sum As Range _
, ByVal col_cond1 As Integer, ByVal cond1 As String _
, ByVal col_cond2 As Integer, ByVal cond2 As String)
Dim letab() As Integer
If col_cond1 > 0 And col_cond2 > 0 Then
cpt = 0
For Each cell In col_sum
If Cells(cell.Row, col_cond1) = cond1 And Cells(cell.Row, col_cond2) = cond2 Then
ReDim Preserve letab(cpt) As Integer
letab(cpt) = cell.Value
cpt = cpt + 1
End If
Next
ElseIf NOT (col_cond2 > 0) Then
'a completer
End If
'on va chercher la mediane
perso_mediane = cherche_mediane(letab)
End Function
Function cherche_mediane(ByRef montab() As Integer)
'on trie
For i = LBound(montab) To UBound(montab)
lemin = montab(i)
y_min = i
For y = i + 1 To UBound(montab)
If montab(y) < lemin Then
y_min = y
lemin = montab(y_min)
End If
Next y
tmp = montab(i)
montab(i) = montab(y_min)
montab(y_min) = tmp
Next i
'on prend la mediane
nb_valeur = UBound(montab) + 1
If nb_valeur = 1 Then
cherche_mediane = montab(0)
Exit Function
End If
If nb_valeur = 2 Then
cherche_mediane = (montab(0) + montab(1)) / 2
Exit Function
End If
'si tableau vide
If nb_valeur Mod 2 = 0 Then
cherche_mediane = (montab((nb_valeur) / 2) + montab((nb_valeur) / 2 + 1)) / 2
Else
cherche_mediane = montab((nb_valeur + 1) / 2)
End If
End Function