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 |
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 |
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 |
All times are GMT +1. The time now is 06:58 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com