|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub TEST9()
Dim ar, br, i&, j&, r&, dic(1 To 2) As New Dictionary, vKey, iPosCol&
Application.ScreenUpdating = False
ReDim ar(1 To 2)
For i = 1 To 2
ar(i) = Cells(1, (i - 1) * 3 + 1).CurrentRegion.Value
For j = 2 To UBound(ar(i))
dic(i)(ar(i)(j, 1) & "," & ar(i)(j, 2)) = Empty
Next j
Next i
ReDim br(1 To UBound(ar(1)) + UBound(ar(2)), 1 To 3)
ReDim ar(1 To 3)
For i = 1 To UBound(ar)
ar(i) = br
Next i
For Each vKey In dic(2).Keys
If dic(1).Exists(vKey) Then
ar(3)(1, 3) = ar(3)(1, 3) + 1
ar(3)(ar(3)(1, 3), 1) = Split(vKey, ",")(0)
ar(3)(ar(3)(1, 3), 2) = Split(vKey, ",")(1)
Else
ar(2)(1, 3) = ar(2)(1, 3) + 1
ar(2)(ar(2)(1, 3), 1) = Split(vKey, ",")(0)
ar(2)(ar(2)(1, 3), 2) = Split(vKey, ",")(1)
End If
Next
For Each vKey In dic(1).Keys
If Not dic(2).Exists(vKey) Then
ar(1)(1, 3) = ar(1)(1, 3) + 1
ar(1)(ar(1)(1, 3), 1) = Split(vKey, ",")(0)
ar(1)(ar(1)(1, 3), 2) = Split(vKey, ",")(1)
End If
Next
For j = 1 To UBound(ar)
iPosCol = (j - 1) * 3 + 7
Cells(1, iPosCol).CurrentRegion.Offset(1).ClearContents
Cells(2, iPosCol).Resize(ar(j)(1, 3), 2) = ar(j)
Next j
Erase dic
Application.ScreenUpdating = True
Beep
End Sub
|
|