Private Sub Worksheet_Change(ByVal Target As Range)
Dim datref As Date, tablo, d As Object, dd As Object, i&, nom$, dat, n&
datref = [DateRef] 'cellule nommée
tablo = [Tableau1].Resize(, 3) 'tableau structurée
Set d = CreateObject("Scripting.Dictionary")
Set dd = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(tablo)
nom = tablo(i, 1)
dat = tablo(i, 3)
If nom <> "" Then
If Not d.exists(nom) Then d(nom) = "": dd(nom) = 0
If IsDate(dat) Then
dat = CDate(dat)
If dat <= datref Then If dat > dd(nom) Then d(nom) = tablo(i, 2): dd(nom) = dat
End If
End If
Next
'---restitution---
Application.EnableEvents = False 'désactive les évènements
On Error Resume Next
n = d.Count
With [Tableau2] 'tableau structuré
.Columns(1).Resize(n) = Application.Transpose(d.keys) 'Transpose est limitée à 65536 lignes
.Columns(2).Resize(n) = Application.Transpose(d.items)
.Offset(n).Resize(.Rows.Count - n).Delete xlUp 'RAZ en dessous
End With
Application.EnableEvents = True 'réactive les évènements
End Sub