|
Sub tt()
Dim arr, brr, crr() As String, k%, DicA As Object, DicB As Object
Set DicA = CreateObject("scripting.dictionary")
Set DicB = CreateObject("scripting.dictionary")
arr = Sheet1.Range("c3:d" & Sheet1.Range("c65536").End(3).Row)
brr = Sheet2.Range("g3:h" & Sheet2.Range("g65536").End(3).Row)
k = 1
For i = 1 To UBound(arr)
DicA(arr(i, 1) & "-" & arr(i, 2)) = "" '表一装入字典
Next
For i = 1 To UBound(brr)
DicB(brr(i, 1) & "-" & brr(i, 2)) = "" '表二装入字典
Next
For Each d In DicA.keys
If Not DicB.exists(d) Then
ReDim Preserve crr(1 To 2, 1 To k)
crr(1, k) = VBA.Split(d, "-")(0)
crr(2, k) = VBA.Split(d, "-")(1)
k = k + 1
End If
Next
'装入数据
If k > 1 Then
Sheet2.Range("g" & Sheet2.Range("g65536").End(3).Row + 1).Resize(UBound(crr, 2), 2) = _
Application.WorksheetFunction.Transpose(crr)
End If
End Sub |
|