用VBA数组字典实现多条件查找

Sub test()
Dim arr, brr
Dim i&, j&
Set d = CreateObject("Scripting.Dictionary")
arr = [A1].CurrentRegion
brr = [A11].CurrentRegion
For i = 2 To UBound(arr)
    d(arr(i, 1) & arr(i, 2)) = i
Next
For j = 2 To UBound(brr)
    If d.Exists(brr(j, 1) & brr(j, 2)) Then
        m = d(brr(j, 1) & brr(j, 2))
        brr(j, 3) = arr(m, 3)
        brr(j, 4) = arr(m, 4)
    End If
Next
[A11].Resize(UBound(brr), 4) = brr
End Sub

  

posted @ 2020-05-03 09:04  天涯海角路  阅读(1877)  评论(0编辑  收藏  举报