Option Explicit
Sub test()
Dim arr, i, j, a, b
arr = [a2:b11].Value
Call rnddata(arr, 1, UBound(arr, 1), 1, UBound(arr, 2))
ReDim brr(1 To UBound(arr, 1), 1 To 4), m(UBound(brr, 2))
a = 1: b = 0
For i = 1 To UBound(arr, 1)
For j = 1 To arr(i, 2)
b = b + 1: m(b) = m(b) + 1
brr(a, b) = arr(i, 1)
If b = UBound(brr, 2) Then a = a + 1: b = 0
Next
Next
For i = 1 To UBound(brr, 2)
Call rnddata(brr, 1, m(i), i, i)
Next
[d2].Resize(UBound(brr, 1), UBound(brr, 2)) = brr
End Sub
Function rnddata(arr, first, last, left, right)
Dim i As Long, j As Long, n As Long, cnt As Long, t
cnt = last - first + 1
Randomize
For i = first To last
n = Int(Rnd * cnt)
For j = left To right
t = arr(i, j): arr(i, j) = arr(first + n, j): arr(first + n, j) = t
Next
Next
End Function |