Sub asda()
Dim i As Long, lr As Long, dic As Object, dk As String, arr, data, kq, a As Long
Set dic = CreateObject("scripting.dictionary")
With Sheets("sheet1")
lr = .Range("A" & Rows.Count).End(xlUp).Row
arr = .Range("A2:B" & lr).Value
For i = 1 To UBound(arr)
dk = arr(i, 1) & "A"
If Not dic.exists(dk) Then
dic.Add dk, ""
End If
Next i
End With
With Sheets("sheet2")
lr = .Range("A" & Rows.Count).End(xlUp).Row
data = .Range("A2:B" & lr).Value
ReDim kq(1 To UBound(arr) + UBound(data), 1 To 2)
For i = 1 To UBound(data)
dk = data(i, 1) & "A"
If Not dic.exists(dk) Then
dic.Add dk, ""
a = a + 1
kq(a, 1) = data(i, 1)
kq(a, 2) = data(i, 2)
End If
dk = data(i, 1) & "B"
If Not dic.exists(dk) Then
dic.Add dk, ""
End If
Next i
For i = 1 To UBound(arr)
dk = arr(i, 1) & "B"
If Not dic.exists(dk) Then
dic.Add dk, ""
a = a + 1
kq(a, 1) = arr(i, 1)
kq(a, 2) = arr(i, 2)
End If
Next i
End With
With Sheets("sheet3")
.Range("A2:B1000").ClearContents
If a Then .Range("A2:B2").Resize(a).Value = kq
End With
Set dic = Nothing
End Sub