Option Explicit
Sub test2()
Dim br, i&
br = [A1].CurrentRegion.Value
Call arrGetRnd2(br)
[E1].Resize(UBound(br), UBound(br, 2)) = br
End Sub
Function arrGetRnd2(ByRef ar, Optional ByVal isCol As Boolean)
Dim xNum&, i&, j&, m&, n&, vTemp
Randomize
m = UBound(ar): n = UBound(ar, 2)
If isCol Then vTemp = m: m = n: n = vTemp
For i = 1 To m
xNum = Int((m - i + 1) * Rnd() + i)
For j = 1 To n
If isCol Then
vTemp = ar(j, xNum): ar(j, xNum) = ar(j, i): ar(j, i) = vTemp
Else
vTemp = ar(xNum, j): ar(xNum, j) = ar(i, j): ar(i, j) = vTemp
End If
Next
Next
End Function
|