|
楼主 |
发表于 2015-2-12 09:55
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 异同项() '佛山小老鼠回答了我的问题,但没有解决A列重复项提取的问题
Dim DicA, DicB, DicC, arrA, arrB, x&, y&, k&, a&, b&, arr1, arr2
Dim AyesBno(1 To 100, 1 To 1), AyesByes(1 To 100, 1 To 1), AnoByes(1 To 100, 1 To 1)
Dim i&, ii&, iii&, j&
Set DicA = CreateObject("Scripting.Dictionary")
Set DicB = CreateObject("Scripting.Dictionary")
Set DicC = CreateObject("Scripting.Dictionary")
a = Cells(Rows.Count, 1).End(xlUp).Row
b = Cells(Rows.Count, 2).End(xlUp).Row
arrA = Range("A1:A" & a)
arrB = Range("B1:B" & b)
For x = 1 To UBound(arrA)
If Not DicA.exists(arrA(x, 1)) Then
DicA(arrA(x, 1)) = ""
DicC(arrA(x, 1)) = ""
End If
Next x
For y = 1 To UBound(arrB)
If Not DicB.exists(arrB(y, 1)) Then
DicB(arrB(y, 1)) = ""
DicC(arrB(y, 1)) = "" ?
End If
Next y
arr1 = DicA.keys 'arr1,arr2
arr2 = DicB.keys
'================================================
On Error Resume Next
For j = 0 To DicA.Count - 1
DicB.Add arr1(j), ""
If ERR.Number = 0 Then
i = i + 1
AyesBno(i, 1) = arr1(j)
Else
ii = ii + 1
AyesByes(ii, 1) = arr1(j)
End If
ERR = 0
Next j
'==========================================
For k = 0 To DicB.Count - 1
DicA.Add arr2(k), ""
If ERR.Number = 0 Then
iii = iii + 1
AnoByes(iii, 1) = arr2(k)
End If
ERR = 0
Next k
[D1] = "A?B?斑??"
[D2].Resize(DicC.Count, 1) = Application.Transpose(DicC.keys)
[E1] = "A?B???"
[E2].Resize(ii, 1) = AyesByes
[f1] = "A?ΤB?⊿Τ?"
[F2].Resize(i, 1) = AyesBno
[G1] = "A?⊿ΤB?Τ"
[G2].Resize(iii, 1) = AnoByes
Range("D1:G1").EntireColumn.AutoFit
End Sub |
|