Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Randomize cells in single column
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 |
#2
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Randomize cells in single column
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 "Guy" wrote: 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 |
#3
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Randomize cells in single column
Perfect!!!
Thanks a bunch! Guy "Mike H" wrote: 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 "Guy" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
randomize a set of numbers in 1 column that are located in another | Excel Worksheet Functions | |||
Can I randomize numbers ALREADY in a column? | Excel Worksheet Functions | |||
Copying a column of single cells into a column of merged cells | Excel Discussion (Misc queries) | |||
Copy column range of "single word" cells with spaces to a single c | Excel Discussion (Misc queries) | |||
I need to randomize a column of alphanumeric employee ID's for a . | Excel Worksheet Functions |