|
Option Explicit
Sub TEST6()
Dim ar, br, i&, j&, r&, dic As Object, vKey
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
ar = [A1].CurrentRegion.Value
For i = 2 To UBound(ar)
dic(ar(i, 1)) = dic(ar(i, 1)) & "," & ar(i, 2)
Next i
ReDim br(1 To UBound(ar), 1 To 10)
For Each vKey In dic.keys
ar = Split(dic(vKey), ",")
ar = transArrToRow(ar, 10, 1, UBound(ar))
r = r + 1
br(r, 1) = vKey
For i = 1 To UBound(ar)
r = r + 1
For j = 1 To UBound(ar, 2)
br(r, j) = ar(i, j)
Next j
Next i
r = r + 1
Next
Columns("F:O").Clear
[f1].Resize(r, UBound(br, 2)) = br
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub
Function transArrToRow(ByVal ar, ByVal iCutNum&, _
ByVal iStartCol&, ByVal iEndCol&) As Variant()
Dim br, j&, n&, y&, x&, iColSize&
If iStartCol < LBound(ar) Then iStartCol = LBound(ar)
If iEndCol > UBound(ar) Then iEndCol = UBound(ar)
n = -(Int(-(iEndCol - iStartCol + 1) / iCutNum))
iColSize = IIf(iEndCol - iStartCol + 1 < iCutNum, iEndCol - iStartCol + 1, iCutNum)
ReDim br(1 To n, 1 To iColSize)
n = 0
For j = iStartCol To iEndCol
n = n + 1
y = -Int(-n / iCutNum)
x = IIf(n Mod iCutNum = 0, iCutNum, n Mod iCutNum)
br(y, x) = ar(j)
Next j
transArrToRow = br
End Function
|
|