+ Reply to Thread
Results 1 to 5 of 5

How many combinations?

  1. #1
    Registered User
    Join Date
    02-10-2007
    Posts
    3

    How many combinations?

    I am just beginning to use excel and am fairly ingnorant about databases and computers, in general. I would appreciate it if someone could tell me if the following calculation can be done and, if so, how.

    If I have a meat column with

    Beef
    Chicken
    Fish

    and a veggie column with

    Broccoli
    Green Beans
    Carrots

    Is there a formula I can use that will list all the possible combinations of the items in the columns using only one item from each list?

    I want the results to look something like this:

    Beef Broccoli
    Beef Green Beans
    Beef Carrots
    Chicken Broccoli
    Chicken Green Beans
    Chicken Carrots
    Fish Broccoli
    Fish Green Beans
    Fish Carrots

    Thanks,
    JLB329

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Does this help

    VBA Noob
    Attached Files Attached Files
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    02-10-2007
    Posts
    3
    Yes, it does help. Thank you.

    How does it work?

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,


    =OFFSET($A$1,MOD(INT((ROW(A1)-1)/COUNTA($A$1:$A$3)),3),0)&" "&INDEX($B$1:$B$3,MATCH(OFFSET($A$1,MOD((ROW(A1)-1),COUNTA($A$1:$A$3)),0),$A$1:$A$3,0))

    It uses the offset function. I set A1 as the starting point then using other formulas to generate numbers to change the offset.

    e.g The below returns A2. 1 column Down and 0 columns across
    =OFFSET($A$1,1,0)

    This part returns 000 then 111 then 222
    =MOD(INT((ROW(A1)-1)/COUNTA($A$1:$A$3)),3)
    So together it looks at A1,A2,A3. Change the if you had 4 condtions just change the bold. Note COUNTA($A$1:$A$3) is another way to return 3
    =OFFSET($A$1,MOD(INT((ROW(A1)-1)/COUNTA($A$1:$A$3)),3),0)

    The 2nd part

    This returns 0,1,2
    =MOD((ROW(A1)-1),COUNTA($A$1:$A$3))
    Then using the index function is looks at offset of A1 and returns B1,B2 etc
    INDEX($B$1:$B$3,MATCH(OFFSET($A$1,MOD((ROW(A1)-1),COUNTA($A$1:$A$3)),0),$A$1:$A$3,0))
    HTH

    VBA Noob

  5. #5
    Registered User
    Join Date
    02-10-2007
    Posts
    3
    Thank you again!

+ 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