Private Sub Worksheet_Activate()
ThisWorkbook.RefreshAll 'commande Actualiser tout
End Sub
Private Sub Worksheet_Calculate()
Dim d As Object, resu(), numpiv%, tablo, i&, x$, n&, lig&
Set d = CreateObject("Scripting.Dictionary")
d.CompareMode = vbTextCompare 'la casse est ignorée
ReDim resu(1 To Rows.Count, 1 To 4) '4 colonnes
For numpiv = 1 To 2
tablo = PivotTables(numpiv).TableRange1 'matrice, plus rapide
For i = 3 To UBound(tablo)
x = tablo(i, 1) & Chr(1) & tablo(i, 2) & Chr(1) & tablo(i, 3)
If x <> Chr(1) & Chr(1) And Not x Like "Total*" Then
If Not d.exists(x) Then
n = n + 1
d(x) = n 'mémorise la ligne
resu(n, 1) = tablo(i, 1): resu(n, 2) = tablo(i, 2): resu(n, 3) = tablo(i, 3)
End If
lig = d(x)
resu(lig, 4) = resu(lig, 4) + 1 'comptage
End If
Next i, numpiv
'---restitution---
Application.ScreenUpdating = False
If FilterMode Then ShowAllData 'si la feuille est filtrée
Application.EnableEvents = False 'désactive les évènements
With [A27] '1ère cellule de destination, à adapter
If n Then
.Resize(n, 4) = resu
.Resize(n, 4).Sort .Cells, xlAscending, Header:=xlNo 'tri sur la 1ère colonne
End If
.Offset(n).Resize(Rows.Count - n - .Row + 1, 4).ClearContents
End With
With UsedRange: End With 'actualise la barre de défilement verticale
Application.EnableEvents = True 'réactive les évènements
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Worksheet_Calculate 'lance la macro
End Sub