+ Reply to Thread
Results 1 to 3 of 3

Making a list of all possible combinations

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-21-2007
    Posts
    196

    Making a list of all possible combinations

    I have the Letters A to U and I want to make a list of all possible combinations of 4 of these letters (e.g. ABCD,ABCE,ABCF,FGHI,TRSA and so on). The order of the letters is not important so ABCD is same as BACD.

    Hope someone will be able to help.

    Any help or advice gratefully received,

    Jack

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Making a list of all possible combinations

    Here you go:

    Sub Combinations()
    
    Dim rngWriteCell As Range
    Dim l1 As Long, l2 As Long, l3 As Long, l4 As Long
    Dim sThisCombo
    
    ThisWorkbook.Sheets(1).Cells.Clear
    Set rngWriteCell = ThisWorkbook.Sheets(1).Cells(1, 1)
    
    For l1 = 0 To 17
      For l2 = l1 + 1 To 18
        For l3 = l2 + 1 To 19
          For l4 = l3 + 1 To 20
            sThisCombo = Chr(65 + l1) & Chr(65 + l2) & Chr(65 + l3) & Chr(65 + l4)
            rngWriteCell.Value = sThisCombo
            Set rngWriteCell = rngWriteCell.Offset(1, 0)
          Next l4
        Next l3
      Next l2
    Next l1
      
    
    End Sub
    A total of 5,985 combinations.

  3. #3
    Forum Contributor
    Join Date
    09-21-2007
    Posts
    196

    Re: Making a list of all possible combinations

    That is absolutely excellent thank you

    Jack

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1