'跟你的示例结果不一样
Option Explicit
Sub test()
Dim arr, brr, m, dic
Set dic = CreateObject("scripting.dictionary")
arr = Range("c3:d" & Cells(Rows.Count, "c").End(xlUp).Row)
brr = Range("f3:g" & Cells(Rows.Count, "f").End(xlUp).Row)
ReDim crr(1 To Rows.Count, 1 To 2) As String
Call fc(arr, brr, crr, dic, "l3")
Call fc(brr, arr, crr, dic, "i3")
End Sub
Function fc(arr, brr, crr, dic, rng)
Dim i, j, m
dic.RemoveAll
For i = 1 To UBound(arr, 1)
dic(arr(i, 1) & arr(i, 2)) = vbNullString
Next
For i = 1 To UBound(brr, 1)
If Not dic.exists(brr(i, 1) & brr(i, 2)) Then
m = m + 1
crr(m, 1) = brr(i, 1): crr(m, 2) = brr(i, 2)
End If
Next
With Range(rng)
.Resize(Rows.Count - 2, 2).ClearContents
If m > 0 Then .Resize(m, 2) = crr
End With
End Function |