Sub Tri_Max()
Dim dur#, dest As Range, ncol%, t, d As Object, i&, x$, a, b, rest(), n&, j%
dur = Timer
Set dest = Feuil1.[E1] '1ère cellule du 2ème tableau, à adapter
Application.ScreenUpdating = False
If dest.Parent.FilterMode Then dest.Parent.ShowAllData 'si la feuille est filtrée
With Feuil1.[A1].CurrentRegion
.Rows(1).Copy dest 'en-têtes
ncol = .Columns.Count
t = .Resize(, IIf(ncol = 1, 2, ncol)).Value2 'matrice, plus rapide, au moins 2 éléments
End With
Set d = CreateObject("Scripting.Dictionary")
For i = 2 To UBound(t)
If d.exists(t(i, 1)) Then
x = d(t(i, 1))
If Val(t(i, 2)) > Val(Left(x, InStr(x, Chr(1)) - 1)) Then d(t(i, 1)) = t(i, 2) & Chr(1) & i
Else
d(t(i, 1)) = t(i, 2) & Chr(1) & i 'date + ligne
End If
Next
If d.Count Then
a = d.keys: b = d.items
ReDim rest(1 To d.Count, 1 To ncol)
For i = 1 To UBound(rest)
rest(i, 1) = a(i - 1)
x = b(i - 1)
n = Mid(x, InStr(x, Chr(1)) + 1)
For j = 2 To ncol
rest(i, j) = t(n, j)
Next j, i
dest(2).Resize(i - 1, ncol) = rest 'resttitution
dest.Resize(i, ncol).Sort dest, xlAscending, Header:=xlYes 'tri sur la 1ère colonne
dest(1, 2).EntireColumn.NumberFormat = "dd/mm/yyyy" 'au cas où
End If
dest(2).Offset(d.Count).Resize(Rows.Count - d.Count - dest.Row, ncol).ClearContents 'RAZ en dessous
dest.EntireColumn.Resize(, ncol).AutoFit 'ajustement largeur
Application.ScreenUpdating = True
MsgBox d.Count & " " & dest & " récupérés en " & Format(Timer - dur, "0.00 \s") 'mesure facultative
End Sub