Randomize cells in single column

G

Guy

Please excuse the duplicate posting.
I need a VBA code that will randomly sort all selected cells in a 'Single'
column (E). In the previous posting yesterday I was given a code that would
random sort but only in 'Multiple' columns and I can't figure out how to get
it to work on just a single column. Can someone please help this amateur?
Again, please excuse the duplicate posting.

Thanks,
Guy
 
M

Mike H

Hi,

With apologies to the original author (Who I can't remember) right click
your sheet tab, view code and paste this in. Select your data and run the code

Sub MixEmUp()
Dim T As Variant
Dim MyArray As Variant
Dim rng As Range
Dim i As Integer, i1 As Integer
Dim j As Integer, j1 As Integer
Set rng = Selection
MyArray = rng.Value
For i = UBound(MyArray, 1) To 1& Step -1&
For j = UBound(MyArray, 2) To 1& Step -1&
i1 = Int(Rnd() * i) + 1&
j1 = Int(Rnd() * j) + 1&
T = MyArray(i, j)
MyArray(i, j) = MyArray(i1, j1)
MyArray(i1, j1) = T
Next j
Next i
rng.Value = MyArray
End Sub

Mike
 
G

Guy

Perfect!!!
Thanks a bunch!
Guy

Mike H said:
Hi,

With apologies to the original author (Who I can't remember) right click
your sheet tab, view code and paste this in. Select your data and run the code

Sub MixEmUp()
Dim T As Variant
Dim MyArray As Variant
Dim rng As Range
Dim i As Integer, i1 As Integer
Dim j As Integer, j1 As Integer
Set rng = Selection
MyArray = rng.Value
For i = UBound(MyArray, 1) To 1& Step -1&
For j = UBound(MyArray, 2) To 1& Step -1&
i1 = Int(Rnd() * i) + 1&
j1 = Int(Rnd() * j) + 1&
T = MyArray(i, j)
MyArray(i, j) = MyArray(i1, j1)
MyArray(i1, j1) = T
Next j
Next i
rng.Value = MyArray
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top