Andreas said:
If I had the numbers 1, 2, 3, 4, 5, 6 then that is combination 1 of 3838380.
If I had the numbers 1, 2, 3, 4, 5, 7 then that is combination 2 of 3838380.
If I had the numbers 35, 36, 37, 38, 39, 40 then that is combination
3838380 of 3838380
If I had the numbers 3, 12, 17, 24, 32, 36 then that is combination ????
of 3838380
I am assuming that the combinations are always listed in ascending order
Here's one play to tinker with ..
1. We'll use a sub by Myrna Larson to generate all 3.8+ mil combinations in
the pick 6 out of 40 [COMBIN(40,6)]. Myrna's sub will list the combos
(strings) in ascending sequence down-then-across, zig-zagging from col A to
col B to col C ...
2. Then we'll use a UDF by Don Pistulka in a formula to derive the end
result for the strings to be queried
The play ..
Here's a link from my archives to a sample book*
with Myrna Larson's sub implemented:
http://savefile.com/files/1635536
MyrnaLarson_Combination_Permutation.xls
*Full details inside
Note: Save the file to your harddisk first, then open the file from there
In Sheet1, just make the settings as:
In A1: C
In B1: 6
Fill the numbers 1-40 within A3:A42
Select A1, then click the button ListPermutations to run Myrna's sub
**Leave it to run say, overnight (or longer)**
When the run's complete, the results will be written in a new sheet to the
left, with cols A to BF* filled with all the 3,838,380 combinations in
sequence such as:
*as COMBIN(40,6) = 3,838,380 combos,
divided by 65536 rows per col = 58.56 cols (col BF is the 58th col, from
left)
The results will be written in a new sheet (Sheet2) to the left
In Sheet2,
In A1:A65536 would be
1, 2, 3, 4, 5, 6
1, 2, 3, 4, 5, 7
1, 2, 3, 4, 5, 8
.....
1, 2, 18, 22, 23, 27
1, 2, 18, 22, 23, 28
In B1:B65536 (result in B1 continues from A65536)
1, 2, 18, 22, 23, 29
1, 2, 18, 22, 23, 30
....
1, 3, 18, 19, 23, 32
1, 3, 18, 19, 23, 33
In C1:C65536 (result in C1 continues from B65536)
1, 3, 18, 19, 23, 34
1, 3, 18, 19, 23, 35
....
and so on, in a zig-zag manner till just after mid-way down col BF
Name the output range in cols A to BF
Click Insert > Name > Define
Names in workbook: RData
Refers to: =Sheet2!$A:$BF
Then press Alt+F11 to go to VBE
Click Insert > Module
Copy n Paste the Functions (by Don Pistulka) below
into the code window on the right
(everything within the dotted lines)
'--------
Function RowN(myrange As Range, Myvalue)
For Each c In myrange.Cells
If c.Value = Myvalue Then
RowN = c.Row
Exit Function
Else
End If
Next c
RowN = "Not Found"
End Function
Function ColN(myrange As Range, Myvalue)
For Each c In myrange.Cells
If c.Value = Myvalue Then
ColN = c.Column
Exit Function
Else
End If
Next c
ColN = "Not Found"
End Function
'----------
Press Alt+Q to get back to Excel
In a new sheet,
list the combo strings to be queried in say, A1 down.
Eg:
1, 2, 18, 22, 24, 28
1, 3, 18, 19, 24, 33
1, 2, 18, 22, 24, 29
2, 8, 11, 24, 31, 34
1, 7, 16, 31, 32, 38
(with digits in ascending sequence, separated by a comma-space)
Then put in B1:
=IF(A1="","",65536*(ColN(RData,A1)-1)+RowN(RData,A1))
Copy B1 down
Col B will return the required results, viz.:
1, 2, 18, 22, 24, 28 65552
1, 3, 18, 19, 24, 33 131088
1, 2, 18, 22, 24, 29 65553
2, 8, 11, 24, 31, 34 851970
1, 7, 16, 31, 32, 38 327681
---