Re nunos31,
Salut patrick1957
Comme ceci :
Option Explicit
Sub test()
Dim a, w(), x(), e, i As Long, n As Long, dico As Object
Set dico = CreateObject("Scripting.Dictionary")
dico.comparemode = 1
With Sheets("Matrice")
a = .Range("a1").CurrentRegion.Value
For i = 2 To UBound(a, 1)
dico.Item(a(i, 2)) = VBA.Array(a(i, 1), Empty)
Next
With Sheets("Old")
a = .Range("a1").CurrentRegion.Value
For i = 2 To UBound(a, 1)
If dico.exists(a(i, 1)) Then
w = dico.Item(a(i, 1))
If IsEmpty(w(1)) Then
ReDim x(1 To 4, 1 To 1)
Else
x = w(1)
ReDim Preserve x(1 To 4, 1 To UBound(x, 2) + 1)
End If
x(1, UBound(x, 2)) = a(i, 1)
x(2, UBound(x, 2)) = w(0)
x(3, UBound(x, 2)) = a(i, 2)
x(4, UBound(x, 2)) = a(i, 4)
w(1) = x
dico.Item(a(i, 1)) = w
End If
Next
For Each e In dico.keys
If IsEmpty(dico.Item(e)(1)) Then dico.Remove e
Next
End With
With .Range("e1").CurrentRegion
With .Offset(1)
.Clear
If dico.Count > 0 Then
For i = 0 To dico.Count - 1
.Offset(n).Resize(UBound(dico.items()(i)(1), 2)) = _
Application.Transpose(dico.items()(i)(1))
n = n + UBound(dico.items()(i)(1), 2)
Next
Else
MsgBox "aucune donnée à restituer"
End If
End With
End With
End With
Set dico = Nothing
End Sub
klin89