|
楼主 |
发表于 2023-10-24 10:01
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
老师您好,您帮忙写的代码,最终结果想要标记红色这条记录下移到下面,您的代码我尝试修改了一下,可是结果还是不对,烦请帮忙不吝再指导一下代码该怎么修改,谢谢!
Sub 比对写法2()
Dim arr, brr, crr(1 To 1000, 1 To 7)
Dim d, d1
Set d = CreateObject("scripting.dictionary")
Set d1 = CreateObject("scripting.dictionary")
arr = [a1].CurrentRegion
For x = 2 To 13
If Not d.exists(arr(x, 1)) Then Set d(arr(x, 1)) = CreateObject("scripting.dictionary")
If Not d(arr(x, 1)).exists(arr(x, 2)) Then Set d(arr(x, 1))(arr(x, 2)) = CreateObject("scripting.dictionary")
d(arr(x, 1))(arr(x, 2))("a") = arr(x, 3)
Next
brr = [e1].CurrentRegion
For i = 2 To UBound(brr)
If Not d.exists(brr(i, 1)) Then Set d(brr(i, 1)) = CreateObject("scripting.dictionary")
If Not d(brr(i, 1)).exists(brr(i, 2)) Then Set d(brr(i, 1))(brr(i, 2)) = CreateObject("scripting.dictionary")
d(brr(i, 1))(brr(i, 2))("b") = brr(i, 3)
Next
For Each aa In d.keys
For Each bb In d(aa).keys
For Each cc In d(aa)(bb).keys
If cc = "a" Then
n = n + 1
crr(n, 1) = aa
crr(n, 2) = bb
crr(n, 3) = d(aa)(bb)(cc)
Else
m = m + 1
crr(m, 5) = aa
crr(m, 6) = bb
crr(m, 7) = d(aa)(bb)(cc)
End If
Next
Next
If m > n Then
n = m
Else
m = n
End If
Next
[i2].Resize(UBound(crr), 7) = crr
End Sub |
|