Option Explicit
Sub test2()
Dim dic As Object
Dim p As String
Dim i As Long
Dim s, it, n As Long
Set dic = CreateObject("scripting.dictionary")
p = ThisWorkbook.Path
With Workbooks.Open(p & "\1.xlsx").Sheets(1)
With .Cells(1).CurrentRegion
For i = 1 To .Rows.Count
s = .Cells(i, 1).Value
If Not dic.exists(s) Then
Set dic(s) = CreateObject("system.collections.arraylist")
dic(s).Add s
dic(s).Add .Cells(i, 2).Value
dic(s).Add .Cells(i, 3).Value
dic(s).Add Empty
End If
Next
End With
.Parent.Close False
End With
With Workbooks.Open(p & "\2.xlsx").Sheets(1)
With .Cells(1).CurrentRegion
For i = 1 To .Rows.Count
s = .Cells(i, 1).Value
If Not dic.exists(s) Then
Set dic(s) = CreateObject("system.collections.arraylist")
dic(s).Add s
dic(s).Add .Cells(i, 2).Value
dic(s).Add Empty
Else
If dic(s)(1) = "" Then
dic(s).removeat 1
dic(s).Insert 2, .Cells(i, 2).Value
End If
dic(s).removeat 3
End If
dic(s).Add .Cells(i, 3).Value
Next
End With
.Parent.Close False
End With
With Cells(1)
.CurrentRegion.ClearContents
For Each it In dic.items
.Offset(n).Resize(, 4).Value = it.toarray
n = n + 1
Next
.Sort .Columns(1), Header:=xlYes
End With
End Sub