|
- Sub Macro1()
- Dim arr, brr, crr, d, d2, i&, s&
- Dim c As Range, c2 As Range, j%, k%
- Sheet3.Activate
- Set d = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- arr = Sheet1.Range("a1").CurrentRegion
- brr = Sheet2.Range("a1").CurrentRegion
- ReDim crr(1 To 60000, 1 To UBound(arr, 2))
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- d(arr(i, 1)) = i
- Else
- d(arr(i, 1)) = d(arr(i, 1)) & "," & i
- End If
- Next
- For i = 1 To UBound(brr)
- If Not d2.exists(brr(i, 1)) Then
- d2(brr(i, 1)) = i
- Else
- d2(brr(i, 1)) = d2(brr(i, 1)) & "," & i
- End If
- Next
- a = d.keys: b = d.items
- For i = 0 To d.Count - 1
- If d2.exists(a(i)) Then
- x = Split(b(i), ",")
- For j = 0 To UBound(x)
- s = s + 1
- If c Is Nothing Then
- Set c = Cells(s, 1)
- Else
- Set c = Union(c, Cells(s, 1))
- End If
- For k = 1 To UBound(arr, 2)
- crr(s, k) = arr(x(j), k)
- Next
- Next
- x = Split(d2(a(i)), ",")
- For j = 0 To UBound(x)
- s = s + 1
- If c2 Is Nothing Then
- Set c2 = Cells(s, 1)
- Else
- Set c2 = Union(c2, Cells(s, 1))
- End If
- For k = 1 To UBound(arr, 2)
- crr(s, k) = brr(x(j), k)
- Next
- Next
- s = s + 1
- End If
- Next
- ActiveSheet.UsedRange.Clear
- Range("a1").Resize(s, UBound(crr, 2)) = crr
- If Not c Is Nothing Then c.Interior.ColorIndex = 6
- If Not c2 Is Nothing Then c2.Interior.ColorIndex = 10
- End Sub
复制代码 |
|