Option Explicit
Sub test2()
Dim ar, br, cr, i&, j&, strJoin$
Application.ScreenUpdating = False
ar = Range("B1", Cells(Rows.Count, "C").End(xlUp)).Value
ReDim cr(1 To UBound(ar), 1)
For i = 1 To UBound(ar)
br = Split(ar(i, 1), ",")
arrGetRnd1 br
strJoin = ""
For j = 0 To ar(i, 2) - 1
strJoin = strJoin & "," & br(j)
Next j
cr(i, 0) = Mid(strJoin, 2)
strJoin = ""
For j = ar(i, 2) To UBound(br)
strJoin = strJoin & " " & br(j)
Next j
cr(i, 1) = Mid(strJoin, 2)
Next i
Columns("D:E").Clear
[D1].Resize(UBound(cr), 2) = cr
Application.ScreenUpdating = True
Beep
End Sub
Function arrGetRnd1(ByRef ar)
Dim xNum&, i&, n&, vTemp
Randomize
n = UBound(ar)
For i = 0 To UBound(ar)
xNum = Int((n - i + 1) * Rnd() + i)
vTemp = ar(xNum): ar(xNum) = ar(i): ar(i) = vTemp
Next
End Function
|