Private Sub Worksheet_Activate()
Dim d As Object, dmin As Object, dmax As Object, tablo, i&, x$, h#, resu(), a, aa, b, c, nom$, n&, nn&, j&
Set d = CreateObject("Scripting.Dictionary")
Set dmin = CreateObject("Scripting.Dictionary")
Set dmax = CreateObject("Scripting.Dictionary")
tablo = Sheets("BDD").[A1].CurrentRegion.Resize(, 5)
'---analyse du tableau---
For i = 2 To UBound(tablo)
d(tablo(i, 3)) = ""
x = tablo(i, 2) & " " & tablo(i, 3)
h = CDbl(CDate(tablo(i, 5)))
If dmin.exists(x) Then
If h < dmin(x) Then dmin(x) = h
If h > dmax(x) Then dmax(x) = h
Else
dmin(x) = h
dmax(x) = h
End If
Next
'---tableau des résultats---
n = d.Count
If n Then
ReDim resu(n - 1, 2) 'base 0
a = d.keys: aa = dmin.keys: b = dmin.items: c = dmax.items
For i = 0 To UBound(a)
nom = a(i)
resu(i, 0) = nom
nn = 0
For j = 0 To UBound(aa)
If Split(aa(j))(1) = nom Then
nn = nn + 1
resu(i, 1) = resu(i, 1) + b(j)
resu(i, 2) = resu(i, 2) + c(j)
End If
Next j
resu(i, 1) = resu(i, 1) / nn 'moyenne des minima
resu(i, 2) = resu(i, 2) / nn 'moyenne des maxima
Next i
End If
'---restitution---
If FilterMode Then ShowAllData 'si la feuille est filtrée
With [A2] '1ère cellule de restitution, à adapter
If n Then .Resize(n, 3) = resu
.Offset(n).Resize(Rows.Count - n - .Row + 1, 3).ClearContents 'RAZ en dessous
End With
End Sub