+ Reply to Thread
Results 1 to 7 of 7

VBA - Finding unique combinations

  1. #1
    Registered User
    Join Date
    10-26-2010
    Location
    World
    MS-Off Ver
    Excel 2007
    Posts
    27

    VBA - Finding unique combinations

    I have a table with the following data in Excel:

    Christian Florida 1
    Katie Wisconsin 1
    Sean Alabama 2
    Kelly Georgia 2
    Kellyn South Carolina 3
    Matt Texas 3

    What I am trying to do is find all possible combinations based on the numbers without duplicates and set them opposite to each other like this:

    Christian Florida 1 2 Alabama Sean
    Christian Florida 1 2 Georgia Kelly
    Christian Florida 1 3 South Carolina Kellyn
    Christian Florida 1 3 Texas Matt
    Katie Wisconsin 1 2 Alabama Sean
    Katie Wisconsin 1 2 Georgia Kelly
    Katie Wisconsin 1 3 South Carolina Kellyn
    Katie Wisconsin 1 3 Texas Matt
    Sean Alabama 2 3 South Carolina Kellyn
    Sean Alabama 2 3 Texas Matt
    Kelly Georgia 2 3 South Carolina Kellyn
    Kelly Georgia 2 3 Texas Matt

    The VBA code I am currently working with is the following but I get too many combinations. I don't need to combine "1" with another "1" for example and I also don't want combinations shown again in the opposite direction. If a combination of "2" and "3" is displayed I don't need the same combination shown again as "3" and "2".

    Please Login or Register  to view this content.

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA - Finding unique combinations

    Try this:-
    Data sheet1 starting "A1"
    Results sheet2 starting "A1.
    Please Login or Register  to view this content.
    Regards Mick

  3. #3
    Registered User
    Join Date
    10-26-2010
    Location
    World
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: VBA - Finding unique combinations

    Thanks Mick. This seems to move me a step closer, I now have fewer duplicates. I still have 3 combinations too many:

    Christian Florida 1 1 Wisconsin Katie
    Sean Florida 2 2 Georgia Kelly
    Kellyn South Carolina 3 3 Texas Matt

    I am trying to avoid putting identical numbers together. So "1" and "1" or "2" and "2" would not be part of the result.
    Last edited by jeffreybrown; 03-30-2013 at 10:02 AM. Reason: Please don't quote whole posts unless necessary...Thanks.

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA - Finding unique combinations

    Try adding the extension in the line below, shown in red, this gave me the same result as you initial thread.
    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA - Finding unique combinations

    It should be simple like this
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jindon; 03-30-2013 at 08:56 AM.

  6. #6
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA - Finding unique combinations

    Jindon,
    That's a very concise and elegant answer.
    Point well made !!!!

  7. #7
    Registered User
    Join Date
    10-26-2010
    Location
    World
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: VBA - Finding unique combinations

    Mick, thanks! The new code works great and also a big thank you to Jindon.

+ 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