Thanks Thanks:  0
Likes Likes:  0
Results 1 to 6 of 6

Thread: Combinations of 6 numbers from a total 11 numbers

  1. #1
    Board Regular selant's Avatar
    Join Date
    Mar 2009
    Posts
    109
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation 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. #2
    Board Regular
    Join Date
    Oct 2008
    Posts
    175
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default 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.
    Last edited by mosiki; Aug 30th, 2009 at 09:46 AM.

  3. #3
    MrExcel MVP
    Join Date
    Apr 2006
    Posts
    19,209
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    Default 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
    10  adef
    11  bcde
    12  bcdf
    13  bcef
    14  bdef
    15  cdef
    16      
    [Book1]Sheet1
    Kind regards
    PGC

    To understand recursion, you must understand recursion.

  4. #4
    Board Regular selant's Avatar
    Join Date
    Mar 2009
    Posts
    109
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Combinations of 6 numbers from a total 11 numbers

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

    Update : It works as desired..
    Last edited by selant; Aug 30th, 2009 at 04:28 PM. Reason: update

  5. #5
    New Member
    Join Date
    Apr 2013
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default 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. #6
    Board Member
    Join Date
    Nov 2015
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default 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.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •