+ Reply to Thread
Results 1 to 8 of 8

Macro to ORDER unique combinations

  1. #1
    Registered User
    Join Date
    05-01-2014
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    3

    Macro to ORDER unique combinations

    Hi

    I'm not sure if this is possible, but here goes.

    I have three columns of letters

    Screenshot (1).jpg

    Column A is my list of 5 variables
    Columns B and C are my list of unique two digit combinations of column A (done using a macro)

    In column D, with the first row (A and B) being combination number 1, I would like to order the list of columns B and C such that the next on the list is the first combination not to contain either of the previous two values, meaning that the next in the list is row 8 (C and D), it should then loop through the list to find the next unassigned row that doesn't contain either C or D which means the next row will be row 4 (A and E) it then goes back through the list to find the next unassigned row not containing the previous two letters which would be row 5 (B and C) and so on and so on.

    Any help would be much appreciated!

    Many thanks

    Martin
    Last edited by woodsquash; 05-02-2014 at 07:15 AM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro to ORDER unique combinations


    Hi,

    join a workbook with source data and desired result …

    Regards !

  3. #3
    Registered User
    Join Date
    05-01-2014
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to ORDER unique combinations

    Will that still work if I have different numbers of combinations?

    For example, if column A has 8 variables, then the combinations are 28 rows long and the solution will be different than other numbers of variables in column A?

    I may just not be understanding what you've said?

    Many thanks

    Martin

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro to ORDER unique combinations


    Attach a workbook file within source data and desired result !

  5. #5
    Registered User
    Join Date
    05-01-2014
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to ORDER unique combinations

    Hi,

    Attachment below

    Hope this helps

    M
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,869

    Re: Macro to ORDER unique combinations

    I'm not very good with this kind of programming. It looks like your existing macro is creating the permutations in lexicographic order (a very common algorithm for generating permutations (see Wikipedia's article, which describes in basic terms common algorithms for generating permutations http://en.wikipedia.org/wiki/Permutation). Sorting this list into something other than standard lexicographic order looks challenging to me. If this were me, I would probably study the algorithm (might be more work than actually programming the algorithm) until I could see a different algorithm for generating the permutations in the desired order. Off the top of my head, this looks something like:

    1) Start with earliest letter not in previous entry. (1s entry, this is A, 2nd entry this is C, 3rd entry this is A, and so on)
    2) Identify the pairings with this letter that have already by used and the letters used in the previous entry. (2nd entry cannot use A and B, 3rd entry cannot use A, B, C, D, and so on)
    3) After eliminating possibilities, current entry will be result of (1) and the earliest availabe letter not in (2).
    4) Repeat loop for each entry.

    I should probably encourage to do a little research and see if there's a formalized description of this kind of algorithm in the annals of computer science or whatever field this algorithm applies to (part of me has to believe you are not the first one to want to generate a list of permutations like this).

    Wish I could help more.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro to ORDER unique combinations

    It's trivially not possible with three players.

    With four players, you start with AB, then CD (per force), then you're done.

    AB
    CD
    AC
    AD
    BC
    BD


    With five players, just noodling around,

    AB
    CD
    AE
    BC
    AD
    BE
    AC
    BD
    CE
    DE

    That's not a proof, but I'm thinking it's not possible.

    What's the purpose?
    Last edited by shg; 05-03-2014 at 02:44 PM.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro to ORDER unique combinations


    woodsquash, the attached workbook's result doesn't match with the algorithm in your original post,
    can you update the new one according with column Match No ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Unique combinations of 7
    By ricardojaworski in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-18-2013, 11:56 AM
  2. Help calculating frequency of order combinations
    By LukeG11 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-20-2013, 10:23 AM
  3. Macro to concatenate unique combinations??
    By oubravs2b in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-02-2012, 08:29 AM
  4. Generate combinations for a variable number of columns in order
    By q83 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2011, 04:17 PM
  5. [SOLVED] count unique combinations
    By mini in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2006, 07:50 AM

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