LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Shuffling a Data List

Than you Tom,

Just the job. I like the use of an array for doing the spadework.

Don

"Tom Ogilvy" wrote in message
...
here's another: (assuming the list is in a column - as written, starting
in
A1)

Sub Shuffle()
'
' Algorithm from:
' The Art of Computer Programming: _
' SemiNumerical Algorithms Vol 2, 2nd Ed.
' Donald Knuth
' p. 139 [Algorithm P]
'
'
Dim list As Variant
Dim rng As Range
Dim t As Long, j As Long, k As Long
t = 100
Set rng = Range(Cells(1, 1), Cells(1, 1).End(xlDown))
list = rng.Value
t = UBound(list, 1)
j = t
Randomize
For i = 1 To t
k = Rnd() * j + 1
lngTemp = list(j, 1)
list(j, 1) = list(k, 1)
list(k, 1) = lngTemp
j = j - 1
Next
rng.Value = list
End Sub

--
Regards,
Tom Ogilvy

"Don Lloyd" wrote in message
...
Is anyone aware of a simple VBA routine to shuffle the contents of a list

in
random fashion.

Don






 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I change a date to UK format without shuffling the actual Venkatraman Excel Discussion (Misc queries) 3 September 20th 07 04:40 PM
Shuffling Ross Excel Discussion (Misc queries) 1 July 27th 07 05:12 PM
data validation list: how do i 'force' a user to enter data from the list? showsomeidnow Excel Discussion (Misc queries) 4 May 1st 07 05:49 PM
data validation list: how do i 'force' a user to enter data from the list? showsomeidnow Excel Discussion (Misc queries) 2 April 29th 07 11:09 PM
Shuffling Data To Make Lists Match Dmorri254 Excel Worksheet Functions 1 January 14th 05 05:58 PM


All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"