Here is a generalized function for shuffling a 1D long array: (I then show
you how to call it with an array of numbers, 1 to 500) and place this in the
cells A1:A500
Public Function ShuffleArray(varr)
'
' Algorithm from:
' The Art of Computer Programming: _
' SemiNumerical Algorithms Vol 2, 2nd Ed.
' Donald Knuth
' p. 139
'
'
Dim List() As Long
Dim t As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim lngTemp As Long
t = UBound(varr, 1) - LBound(varr, 1) + 1
ReDim List(1 To t)
For i = 1 To t
List(i) = varr(i)
Next
j = t
Randomize
For i = 1 To t
k = Rnd() * j + 1
lngTemp = List(j)
List(j) = List(k)
List(k) = lngTemp
j = j - 1
Next
ShuffleArray = List
End Function
This shows how to call it:
Sub Main()
Dim varr()
Dim varr1
ReDim varr(1 To 500)
For i = 1 To 500
varr(i) = i
Next
varr1 = ShuffleArray(varr)
Range("A1:A500").Value = Application.Transpose(varr1)
End Sub