Sub Filtre_comptes()
'---se lance par les touches Ctrl+F---
Dim dest As Range, tablo, d As Object, col%, c As Range, x$, n&, resu(), i&, y$, nn&, v
Set dest = Sheets("Matrice").[BX3].CurrentRegion
With Sheets("Journal")
If .FilterMode Then .ShowAllData 'si la feuille est filtrée
tablo = .Range("B7:I" & .Cells(Rows.Count, 2).End(xlUp).Row) 'matrice, plus rapide
End With
Set d = CreateObject("Scripting.Dictionary")
d.CompareMode = vbTextCompare 'la casse est ignorée
For col = 1 To dest.Columns.Count Step 2
Set c = dest.Cells(1, col)
x = LCase(Trim(c))
n = 0
ReDim resu(1 To UBound(tablo), 1 To 2) 'réinitialise le tableau des résultats
For i = 1 To UBound(tablo)
If LCase(Trim(tablo(i, 2))) = x Then
y = Trim(tablo(i, 3))
If Not d.exists(y) Then
n = n + 1
d(y) = n 'mémorise la ligne
resu(n, 1) = y
End If
nn = d(y)
v = tablo(i, 8)
If IsNumeric(v) Then resu(nn, 2) = resu(nn, 2) + CDbl(v)
End If
Next i
If n Then c(2).Resize(n, 2) = resu 'restitution
c(2).Offset(n).Resize(Rows.Count - n - c.Row, 2).ClearContents 'RAZ en dessous
Next col
dest.CurrentRegion.Columns.AutoFit 'ajustement largeurs
dest.Parent.Visible = xlSheetVisible 'au cas où
Application.Goto dest 'active la feuille
dest(1).Select
End Sub