|
楼主 |
发表于 2012-5-14 21:10
|
显示全部楼层
字典解法- Sub test()
- Dim i&, Myr&, Arr1, arr2, brr(1 To 1000, 1 To 3)
- Dim d, k, t
- Set d = CreateObject("Scripting.Dictionary")
- Myr = Sheet1.[a65536].End(xlUp).Row
- Arr1 = Sheet1.Range("a1:b" & Myr)
- Myr = Sheet1.[a65536].End(xlUp).Row
- arr2 = Sheet1.Range("e1:f" & Myr)
- For i = 2 To UBound(Arr1)
- k = k + 1
- d(Arr1(i, 1)) = k
- brr(k, 1) = Arr1(i, 1)
- brr(k, 2) = Arr1(i, 2)
- Next
- For i = 2 To UBound(arr2)
- If d.exists(arr2(i, 1)) Then
- brr(d(arr2(i, 1)), 3) = arr2(i, 2)
- Else
- k = k + 1
- d(Arr1(i, 1)) = k
- brr(k, 1) = arr2(i, 1)
- brr(k, 3) = arr2(i, 2)
- End If
-
- Next
- Range("i2:k1000").ClearContents
- Range("i2").Resize(UBound(brr), 3) = brr
- Set d = Nothing
- End Sub
复制代码 |
|