本帖最后由 jiminyanyan 于 2014-8-5 21:16 编辑
我也写了一个,供参考。。。。。- Sub yy1()
- Sheet1.Activate
- Dim arr1, brr1
- Dim dx, dy, arr(1 To 1000, 1 To 4), brr(1 To 1000, 1 To 4), crr(1 To 1000, 1 To 3), drr(1 To 1000, 1 To 3), x, y, s, t, i&, j&, m&, n&
- Set dx = CreateObject("Scripting.Dictionary")
- Set dy = CreateObject("Scripting.Dictionary")
- arr1 = Range("a4:c" & [a65536].End(3).Row).Value
- brr1 = Range("e4:g" & [e65536].End(3).Row).Value
- For i = 1 To UBound(arr1)
- arr(i, 1) = arr1(i, 1)
- arr(i, 2) = arr1(i, 2)
- arr(i, 3) = arr1(i, 3)
- Next
- For i = 1 To UBound(brr1)
- brr(i, 1) = brr1(i, 1)
- brr(i, 2) = brr1(i, 2)
- brr(i, 3) = brr1(i, 3)
- Next
- For i = 1 To UBound(arr)
- dx(arr(i, 1)) = dx(arr(i, 1)) + 1
- arr(i, 4) = dx(arr(i, 1))
- s = arr(i, 1) & arr(i, 2) & arr(i, 3) & arr(i, 4)
- dx(s) = ""
- Next
- For i = 1 To UBound(brr)
- dy(brr(i, 1)) = dy(brr(i, 1)) + 1
- brr(i, 4) = dy(brr(i, 1))
- s = brr(i, 1) & brr(i, 2) & brr(i, 3) & brr(i, 4)
- dy(s) = ""
- Next
- For i = 1 To UBound(arr)
- s = arr(i, 1) & arr(i, 2) & arr(i, 3) & arr(i, 4)
- If dy.exists(s) Then
- Else
- n = n + 1
- crr(n, 1) = arr(i, 1)
- crr(n, 2) = arr(i, 2)
- crr(n, 3) = arr(i, 3)
- End If
- Next
- For i = 1 To UBound(brr)
- s = brr(i, 1) & brr(i, 2) & brr(i, 3) & brr(i, 4)
- If dx.exists(s) Then
- Else
- m = m + 1
- drr(m, 1) = brr(i, 1)
- drr(m, 2) = brr(i, 2)
- drr(m, 3) = brr(i, 3)
- End If
- Next
- If m > 0 Then [i6].Resize(m, 3) = crr
- If n > 0 Then [m6].Resize(n, 3) = drr
- Set dx = Nothing
- Set dy = Nothing
- End Sub
复制代码 |