Private Sub Worksheet_Activate()
Worksheet_Change [B:C] 'lance la macro
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B5:C" & Rows.Count)) Is Nothing Then Exit Sub
Dim r As Range, d As Object, dd As Object, tablo, i&, dat, x$
Set r = Intersect(Target.EntireRow, Range("B5:C" & Rows.Count), UsedRange)
If r Is Nothing Then Exit Sub
'---analyse de la 1ère feuille---
Set d = CreateObject("Scripting.Dictionary")
d.CompareMode = vbTextCompare 'la casse est ignorée
Set dd = CreateObject("Scripting.Dictionary")
dd.CompareMode = vbTextCompare 'la casse est ignorée
tablo = Feuil1.[A2].CurrentRegion.Resize(, 3) 'matrice, plus rapide
For i = 2 To UBound(tablo)
dat = tablo(i, 1)
If IsDate(dat) Then
dat = CDate(dat)
x = tablo(i, 2)
If dat > d(x) Then d(x) = dat: dd(x) = tablo(i, 3)
End If
Next i
'---tableau de cette 2ème feuille---
Application.EnableEvents = False 'désactive les évènements
For Each r In r.Areas 'si entrées/effacements multiples (copier-coller)
tablo = r 'matrice, plus rapide, sur cellules jointives
For i = 1 To UBound(tablo)
tablo(i, 2) = dd(tablo(i, 1))
Next i
r = tablo 'restitution
Next r
Application.EnableEvents = True 'réactive les évènements
End Sub