Thanks:  0
Likes:  0

# Thread: Combinations of 6 numbers from a total 11 numbers

1. ## Combinations of 6 numbers from a total 11 numbers

I want to create 6 numbers from 11 numbers..
lets suppose my numbers are: 1,2,3,4,5,6,7,8,9,10,11
I want to generate all possibilities of the 6 numbers. But i dont want duplicate series.. I mean 1,2,3,4,5,6 and 6,5,4,3,2,1 are duplicates.

ANY HELPS ARE GREATLY APPRECIATED

2. ## Re: Combinations of 6 numbers from a total 11 numbers

=combin(11,6) will give you the number of combinations you are looking for which is 462.

3. ## Re: Combinations of 6 numbers from a total 11 numbers

Hi

This code generates combinations.

- write the set of elements in a continuous range, starting in A1, down (in your case write the numbers in A1:A11)
- write how many numbers are picked up for each combination in B1 (in your case B1=6)
- the result is writen starting in C1

Run this code:

Code:
```Sub Combinations()
Dim rRng As Range, p
Dim vElements, lRow As Long, vresult As Variant

Set rRng = Range("A1", Range("A1").End(xlDown)) ' The set of numbers
p = Range("B1").Value ' How many are picked

vElements = Application.Index(Application.Transpose(rRng), 1, 0)
ReDim vresult(1 To p)
Call CombinationsNP(vElements, CInt(p), vresult, lRow, 1, 1)
End Sub

Sub CombinationsNP(vElements As Variant, p As Integer, vresult As Variant, lRow As Long, iElement As Integer, iIndex As Integer)
Dim i As Integer

For i = iElement To UBound(vElements)
vresult(iIndex) = vElements(i)
If iIndex = p Then
lRow = lRow + 1
Range("C" & lRow).Resize(, p) = vresult
Else
Call CombinationsNP(vElements, p, vresult, lRow, i + 1, iIndex + 1)
End If
Next i
End Sub```

Ex.:

ABCDEF
1a4abcd
2b abce
3c abcf
4d abde
5e abdf
6f abef
7  acde
8  acdf
9  acef
11  bcde
12  bcdf
13  bcef
14  bdef
15  cdef
16
[Book1]Sheet1

4. ## Re: Combinations of 6 numbers from a total 11 numbers

thank you very much, i am trying right now..

Update : It works as desired..

5. ## Re: Combinations of 6 numbers from a total 11 numbers

Hi,

I am trying to use the vb.net code but it is not running. Please assist me get the code working

Thanks

6. ## Re: Combinations of 6 numbers from a total 11 numbers

I want to generate all possibilities of the 5 numbers from 1-49 numbers. But i dont want duplicate series.