Hi
try this
it sorts the selected cells randomly. I assume you want to overwrite the contents of existing cells. If not, modify the
Offset(0,0) to e.g. offset(0,1) to sort into the column adjacent on the right etc
Sub random_sort()
Dim MyCol As New Collection, MyCol2 As New Collection, x As Long, MyRange As Range, z As Long
Set MyRange = Selection
For x = 1 To MyRange.Cells.Count
MyCol.Add MyRange.Cells(x).Value
Next x
For x = MyRange.Cells.Count To 1 Step -1
y = Int((x * Rnd) + 1)
MyCol2.Add MyCol(y)
MyCol.Remove y
Next x
For z = 1 To MyRange.Cells.Count
MyRange.Cells(z).Offset(0, 0) = MyCol2(z)
Next z
End Sub
Bookmarks