+ Reply to Thread
Results 1 to 7 of 7

Combinations

  1. #1
    Forum Contributor
    Join Date
    09-09-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    102

    Combinations

    Hi,

    I have four letters F,P,M,D that I need unique 5 letter combos of i.e. FFFFP, FFFFM, FFFFD, FFFPP and so on. I don't want the same code i.e. PFFFF repeated later on.

    I believe there are 120 combinations of this, is there a way to create a formula to perform this task for me?

    Thanks

    Z

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Combinations

    Try this (enable macros):

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Combinations

    Ignore me. i misread the Q.

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Combinations

    To get all combinations, then you can list the individual letters in cells A1 to A4, and then you can put this formula in B1:

    =IF(ROWS($1:1)>COUNTA(A:A)^5,"",INDEX(A:A,MOD(INT((ROWS($1:1)-1)/COUNTA(A:A)^4),COUNTA(A:A))+1)&INDEX(A:A,MOD(INT((ROWS($1:1)-1)/COUNTA(A:A)^3),COUNTA(A:A))+1)&INDEX(A:A,MOD(INT((ROWS($1:1)-1)/COUNTA(A:A)^2),COUNTA(A:A))+1)&INDEX(A:A,MOD(INT((ROWS($1:1)-1)/COUNTA(A:A)),COUNTA(A:A))+1)&INDEX(A:A,MOD(ROWS($1:1)-1,COUNTA(A:A))+1))

    Copy down until you get blanks (i.e. beyond row 1024, which is 4 ^ 5). I'm not sure how you would remove the duplicates from that list.

    Hope this helps.

    Pete

  5. #5
    Forum Contributor
    Join Date
    09-09-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    102

    Re: Combinations

    Thanks Pete, I'd got that far. just want to remove the duplicates.

  6. #6
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,899

    Re: Combinations


    Please Login or Register  to view this content.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Combinations

    Quote Originally Posted by zak.horrocks View Post
    Thanks Pete, I'd got that far. just want to remove the duplicates.
    I'm going out soon, so I don't have time to check into this thoroughly, but with the formula that I gave you earlier copied down column B, you can put this array* formula in C1:

    =IF(B1="","",SUM(10^(MATCH(MID(B1,ROW($1:$5),1),A$1:A$4,0)-1)))

    *Note: an array formula needs to be committed using the key combination of Ctrl-Shift-Enter (CSE), rather than the usual < Enter >.

    When you copy this down it allocates a number to each letter in the cells of column B (a power of 10, so F=1, P=10, M=100, D=1000) and then adds them up. Enter the value 1 in cell D1, then you can put this formula in D2:

    =IF(C2="","",IF(COUNTIF(C$1:C2,C2)>1,"-",MAX(D$1:D1)+1))

    and then copy down - this allocates a unique sequential number only for the first occurrence of the numbers in column C (i.e. it picks out the first of any duplicates in column B).

    Then you can use this formula in E1:

    =IFERROR(INDEX(B:B,MATCH(ROWS($1:1),D:D,0)),"")

    which returns the letter strings that are unique. In my tests it only returns 56 of them, whereas you said there should be 120, and that's the bit that I don't have time to look into right now. I'll attach the file so that you can look into it.

    Hope this helps.

    Pete
    Attached Files Attached Files

+ 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. Combinations
    By lorber123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-29-2016, 07:29 PM
  2. Combinations
    By Prit50 in forum Excel General
    Replies: 5
    Last Post: 12-05-2015, 10:23 AM
  3. Finding possible combinations & listing the wanted combinations
    By Zoke in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 07-16-2012, 03:41 PM
  4. Possible Combinations
    By Please HELP!!! in forum Excel General
    Replies: 1
    Last Post: 01-06-2006, 12:00 PM
  5. getting combinations
    By vecky in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 12-31-2005, 08:40 PM
  6. Combinations
    By osprey in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  7. Combinations
    By osprey in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM

Tags for this Thread

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