Bonjour,
Une fonction matricielle :
Function COMPARSELONNB(pl1 As Range, pl2 As Range)
Dim res(), i%, j%, n1%, n2%, s1, s2
Application.Volatile
If pl1.Columns.Count > 1 Or pl2.Columns.Count > 1 Or pl1.Rows.Count <> pl2.Rows.Count Then
COMPARSELONNB = CVErr(xlErrValue)
Exit Function
End If
ReDim res(1 To pl1.Rows.Count, 1 To 1)
For i = 1 To pl1.Rows.Count
If pl1.Cells(i, 1) <> "" Then
n1 = n1 + 1: s1 = s1 + pl1.Cells(i, 1)
Do
j = j + 1
If j > UBound(res) Then Exit For
If pl2.Cells(j, 1) <> "" Then
n2 = n2 + 1: s2 = s2 + pl2.Cells(j, 1)
If n2 = n1 Then
res(i, 1) = s1 & "//" & s2
Exit Do
End If
End If
Loop While n2 < n1
Else
res(i, 1) = ""
End If
Next i
COMPARSELONNB = res
End Function
Sélectionner plage de cellules E6:E19 (égale aux plages Titi et Toto),
Taper formule : =COMPARSELONNB(D6:D19;C6:C19)
soit en arguments plage Titi puis plage Toto,
Valider par Ctrl+Maj+Entrée (validation matricielle),
Résultats dans la plage sélectionnée, sous la forme : Total Titi//Total Toto même niveau (quand Titi n'a rien, rien n'est affiché)
NB- Si Titi a plus d'occurrence que Toto, le calcul s'interrompt (et les résultats non calculés affichent 0, mais on pourra modifier ça si besoin...)
Cordialement.
Salut H2so4 !