Option Explicit
Sub test2()
Dim br, i&
br = [V4].CurrentRegion
Call arrGetRnd2(br, True)
With [AE4].Resize(UBound(br), UBound(br, 2))
.NumberFormatLocal = "@"
.Value = br
End With
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
|