Sub Maximum()
Dim F As Worksheet, d As Object, dd As Object, tablo, ncol%, i&, x$, n&, resu(), a, j%, dat, nn&, col%
Set F = Sheets("Feuil1") 'nom de la feuille à adapter
Set d = CreateObject("Scripting.Dictionary")
Set dd = CreateObject("Scripting.Dictionary")
tablo = F.[B14].CurrentRegion.Resize(, 9) 'matrice, plus rapide
'---liste des en-têtes de colonnes---
ncol = 1
For i = 2 To UBound(tablo)
x = tablo(i, 9)
If x <> "" Then If Not d.exists(x) Then ncol = ncol + 1: d(x) = ncol
Next i
'---tableau des résultats---
n = 1
ReDim resu(1 To ncol, 1 To 1) 'tableau transposé
resu(1, 1) = tablo(1, 2) 'titre Date
a = d.keys
For j = 2 To ncol: resu(j, 1) = a(j - 2): Next j 'titres
For i = 2 To UBound(tablo)
dat = tablo(i, 2)
If Not dd.exists(dat) Then
n = n + 1
dd(dat) = n 'mémorise le numéro
ReDim Preserve resu(1 To ncol, 1 To n)
resu(1, n) = dat
End If
nn = dd(dat)
col = d(tablo(i, 9))
If col And IsNumeric(tablo(i, 1)) Then If CDbl(tablo(i, 1)) > resu(col, nn) Then resu(col, nn) = CDbl(tablo(i, 1))
Next i
'---transposition des résultats---
ReDim a(1 To n, 1 To ncol)
For i = 1 To n
For j = 1 To ncol
a(i, j) = resu(j, i)
Next j, i
'---restitution sur L14 (cellule à adapter)---
Application.ScreenUpdating = False
If F.FilterMode Then F.ShowAllData 'si la feuille est filtrée
F.[L14].CurrentRegion.Delete xlUp 'RAZ
With F.[L14].Resize(n, ncol)
.Value = a
.Borders.Weight = xlThin 'bordures
.Interior.Color = RGB(221, 235, 247) 'bleu
End With
End Sub