ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how do I create a random list whilst keeping some entries fromrandomizing? (https://www.excelbanter.com/excel-programming/438247-how-do-i-create-random-list-whilst-keeping-some-entries-fromrandomizing.html)

warren dwyer

how do I create a random list whilst keeping some entries fromrandomizing?
 
I need to create a large number of randomly sorted lists from a single master list (random team order per event based on a list of teams entered for all events). Some of the entries must remain in the same order in each list, but the remaining entries must be shuffled.

ie. Teams are A, B, C, D, E, F, G, H, J, K and L . CD and HJK must always appear in the same order. Therefore B.CD.ME.HJK.FAGL, AF.HJK.GMLEB.CD, HJK.FL.CD.EBAGM etc are all valid solutions.

I can create a fully random list easily, but can't find an easy way to keep the important entries in the same order.

Cheers
Waz.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Look Ma, No DataBase! Bamboo Prevalence
http://www.eggheadcafe.com/tutorials...abase-bam.aspx

michdenis

how do I create a random list whilst keeping some entries from randomizing?
 
Hi,

Try this :

'--------------------------------------
Sub test()
Dim Dic As Object, Arr()
Arr = Array("A", "B", "C", "D", "E", _
"F", "G", "H", "J", "K", "L")

Set Dic = CreateObject("Scripting.Dictionary")
Do
Randomize
v = Arr(Int(Int(UBound(Arr) - LBound(Arr) + 1) _
* Rnd + LBound(Arr)))
If Not Dic.Exists(v) Then
Select Case UCase(v)
Case Is = "C", "D"
Dic.Add "C", "C"
Dic.Add "D", "D"
i = i + 2
Case Is = "H", "J", "K"
Dic.Add "H", "H"
Dic.Add "J", "J"
Dic.Add "K", "K"
i = i + 3
Case Else
Dic.Add v, v
i = i + 1
End Select
End If
Loop Until i = UBound(Arr)

With Worksheets("Sheet1")
.Range("A1").Resize(i) = Application.Transpose(Dic.items)
End With
'--------------------------------------



"warren dwyer" a écrit dans le message de groupe de discussion :
...
I need to create a large number of randomly sorted lists from a single master list (random
team order per event based on a list of teams entered for all events). Some of the entries
must remain in the same order in each list, but the remaining entries must be shuffled.

ie. Teams are A, B, C, D, E, F, G, H, J, K and L . CD and HJK must always appear in the
same order. Therefore B.CD.ME.HJK.FAGL, AF.HJK.GMLEB.CD, HJK.FL.CD.EBAGM etc are all
valid solutions.

I can create a fully random list easily, but can't find an easy way to keep the important
entries in the same order.

Cheers
Waz.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Look Ma, No DataBase! Bamboo Prevalence
http://www.eggheadcafe.com/tutorials...abase-bam.aspx


joel[_512_]

how do I create a random list whilst keeping some entries fromrandomizing?
 

Assign the items the same random number in the 1st field and then use a
second field for the order 1,2,3,.... Then sort on the two fields.
Items that are singular just keep the 2nd field empty.


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=168766

Microsoft Office Help



All times are GMT +1. The time now is 01:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com