|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:b" & r)
- zs = .Range("g1")
- ReDim brr(1 To UBound(arr), 1 To zs * 2)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- Set d(arr(i, 2)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 2))(i) = Empty
- Next
- m = 1
- n = 1
- For Each aa In d.keys
- For Each bb In d(aa).keys
- brr(m, n) = arr(bb, 1)
- brr(m, n + 1) = arr(bb, 2)
- n = n + 2
- If n > UBound(brr, 2) Then
- m = m + 1
- n = 1
- End If
- Next
- Next
- .Range("k3").Resize(m, UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|