'你这示例结果是否正确?
Option Explicit
Sub test()
Dim i, j, k, t, arr, brr()
ReDim dic(1 To 2)
For i = 1 To UBound(dic)
Set dic(i) = CreateObject("scripting.dictionary")
Next
arr = [a1].CurrentRegion
For i = 2 To UBound(arr, 1)
For j = 1 To 2
dic(j).RemoveAll
t = Replace(Replace(arr(i, j), ",", ","), Space(1), ",")
t = Split(t, ",")
For k = 0 To UBound(t)
If Len(t(0)) Then dic(j)(t(k)) = vbNullString
Next k, j
If getdata(dic(1), dic(2), brr) Then arr(i, 3) = Join(brr, ",") Else arr(i, 3) = vbNullString
If getdata(dic(2), dic(1), brr) Then arr(i, 4) = Join(brr, ",") Else arr(i, 4) = vbNullString
Next
[a1].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End Sub
Function getdata(dic1, dic2, arr) As Boolean
Dim key, n
For Each key In dic1
If Not dic2.exists(key) Then
n = n + 1: ReDim Preserve arr(1 To n)
arr(n) = key
End If
Next
If n > 0 Then getdata = True
End Function |