View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Excel random sorting query

For an approximate* but "fun" solution
using only worksheet functions,
try playing around with this simple set-up

Fill in A1:A12, the numbers 1 - 12
Put in B1:B12, your 12 numbers
Name the range A1:B12 as say: MyTable

Put in C1: =RAND(), copy down C1:C12

Name the range C1:C12 as say: TBL1

Select D1:D12
Put in the formula bar: =RANK(TBL1,TBL1)
Hold down Ctrl + Shift keys, press Enter
(It's an array formula)

Done correctly, Excel will wrap curly braces around
the formula, viz: {=RANK(TBL1,TBL1)}

(In D1:D12 will be a random shuffle of the numbers 1 - 12
without repeats)

Put in E1: =VLOOKUP(D1,MyTable,2,0)
Copy down to E12

Put in G1: =INDIRECT("E"&6*ROW()-10+COLUMN()-2)
Copy G1 across to L1, then down one row to L2

In G1:L2 will be 2 random unique sets
of 6 numbers from your 12 numbers in B1:B12

Select G1:L2 and
Copy Paste Special Values somewhere else

Press F9 to re-generate another 2 sets in G1:L2
and freeze the values somewhere else

Repeat above until you get the desired number of sets

*Note: It's only an approximation because
there's altogether a total of 924 unique sets of 6 numbers
which can be formed from your set of 12 numbers,
i.e. =COMBIN(12,6) returns 924

There's still the possibility (albeit quite remote)
that the successive sets of 6 numbers generated
with each press of F9 could actually be duplicates
of earlier sets generated, from amongst the total of 924 uniques

But the chances of this happening from the
12 - 13 re-generations (to get your 25 sets) may actually
turn out to be quite remote.

--
hth
Max
-----------------------------------------
Please reply in thread
Use xdemechanik <atyahoo<dotcom for email
--------------------------------------------------------
"fingers" wrote in message
...
Rocky, Edwin,
the list are generating OK but there are duplicated numbers in most of
the lists. How can I modify the script to ensure each list is
different?



---
Message posted from http://www.ExcelForum.com/