View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.newusers
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Scenario Permutations

Just "collapse" it 2 cols at a go starting from the rightmost cols, until
you are left with a final single col (or until you run out of rows to
complete the final copy down, ie hitting xl2003 or earlier's limit of 65536,
whichever comes earlier <g).

Here's an example:

Suppose we have a 2 x 5 x 3 x 4 source which we want to permutate to the
final 120 rows

We could start by placing the rightmost 3 x 4 col items into Sheet1's A1:B4
(this is the example in the earlier response), and then pull the 12
permutations out in Sheet2's B1:B12 by placing in Sheet2's B1:
=OFFSET(Sheet1!$A$1,INT((ROW(A1)-1)/4),)&"
"&OFFSET(Sheet1!$B$1,MOD(ROW(A1)-1,4),)
and copying B1 down by: 3 x 4 = 12 rows to B12. This "collapses" the
rightmost 3 x 4 into a single col in Sheet2's B1:B12.

Then we can paste the 2nd source col's "5" items into Sheet2's A1:A5, and
collapse Sheet2's data accordingly into Sheet3's col B by placing in
Sheet3's B1:
=OFFSET(Sheet2!$A$1,INT((ROW(A1)-1)/12),)&"
"&OFFSET(Sheet2!$B$1,MOD(ROW(A1)-1,12),)
then copy B1 down by: 5 x 12 = 60 rows to B60
(adjust the orig. formula to point to Sheet2 as the new source, change the
number within the INT and MOD to suit the # of items in Sheet2's col B, ie
12 items)

Finally, we paste the first source col's "2" items into Sheet3's A1:A2, and
collapse Sheet3's data into Sheet4's col B.

We place in Sheet4's B1:
=OFFSET(Sheet3!$A$1,INT((ROW(A1)-1)/60),)&"
"&OFFSET(Sheet3!$B$1,MOD(ROW(A1)-1,60),)
then copy B1 down by: 2 x 60 = 120 rows to B120
(similarly adjust the formula to point to Sheet3 as the new source, change
the number within the INT and MOD to suit the # of items in Sheet3's col B,
ie 60 items).

Sheet4's B1:B120 will return the final permutated results
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---
"Mr. X." wrote in message
...
Thank you very much Max. It worked great.

What if you wanted to add additional columns? What part of the formula do
I
need to change.

Thanks again.