+ Reply to Thread
Results 1 to 10 of 10

Sum of 16 numbers out of 25, matching a number

  1. #1
    Registered User
    Join Date
    05-31-2012
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    48

    Sum of 16 numbers out of 25, matching a number

    Hello, alls.

    I have attached an example file.

    I have a serie of 25 various numbers (which can change). I would find all the combinations where 16 among them match a number (which can change).

    Example :

    The series of 25 numbers is : 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 25 - 30 - 35 - 40 - 50

    5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20 (16 numbers) match 200

    1+2+3+4+5+6+7+8+9+10+14+16+20+25+30+40 (16 numbers) match 200 as well.

    Thanks for ny kind help.
    Best.
    Frederic
    Attached Files Attached Files

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Sum of 16 numbers out of 25, matching a number

    Hi Askalian,


    See the attached file and click on the button where I used below code to achieve the desired results:-

    Please Login or Register  to view this content.
    Example 3- chk range for a sum.xlsm

    Regards,
    DILIPandey
    <click on below * if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Registered User
    Join Date
    05-31-2012
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    48

    Re: Sum of 16 numbers out of 25, matching a number

    Hi,

    Thanks for the kind answer.

    Basically, it works well, but maybe I was not precise in my post, but :

    - The 16 numbers must be chosen among those numbers of cells C2 to C26 (I can see other numbers in the results of your calculation).
    - Those 16 numbers must be chosen once only (Sorry, this was not indicated in my post).
    - The sum number (in Cell G5) can be modified.

    Hope this will not need too much changes.
    Thanks for the help.
    Frederic

  4. #4
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Sum of 16 numbers out of 25, matching a number

    Not sure about your above second point.. but see below file to pick up the numbers from c2:c26

    Example 3- chk range for a sum.xlsm

    Regards,
    DILIPandey
    <click on below * if this helps>

  5. #5
    Registered User
    Join Date
    05-31-2012
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    48

    Re: Sum of 16 numbers out of 25, matching a number

    Yes, it works much better with your update.

    The Point 2 means that if one number among the 25 possible choice (c2:c26) is chosen among the 16, it can be only chosen once.
    So, this solution will match :

    5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20 = 200, because each number appears only once.

    but this solution will not match :

    1+1+3+7+7+11+12+12+14+14+16+16+18+18+25+25 = 200, because there are several 1, 7, 12, 14, 16, 18, 25.

    Also, if the sum number (200, in this example) can be variable ?

    Thanks for all your time and skills.
    Best.
    Frederic

  6. #6
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Sum of 16 numbers out of 25, matching a number

    Okay for :-
    if the sum number (200, in this example) can be variable ?
    update below code line in code:-
    While Range("j22").Value <> Range("g5").Value

    see attached:-

    Example 3- chk range for a sum.xlsm

    Regards,
    DILIPandey
    <click on below * if this helps>

  7. #7
    Registered User
    Join Date
    05-31-2012
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    48

    Re: Sum of 16 numbers out of 25, matching a number

    Thanks again, but is there any chance to solve the fact that all 16 values must be unique ?

    Otherwise, it is useless. Let me explain :

    The purpose of this calculation is destinated to see all posible combinations of money gains for a TV gameshow :

    The sum of the 16 numbers (200 in the example) is the maximum winnings of the contestants.

    The 25 possible numbers are each winnings per question (16 questions), but the winnings of each question must be different. This is why all values among the 16 must be unique.

    Thanks if you can find any helpfull update.
    Frederic

  8. #8
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Sum of 16 numbers out of 25, matching a number

    Okay.. for unique thing, try the attached file where I have updated the macro but this will be very lengthy exercise and macro kept running even after running 10 mins

    may be only one combination exists

    Example 3- chk range for a sum.xlsm


    Regards,
    DILIPandey
    <click on below * if this helps>

  9. #9
    Registered User
    Join Date
    05-31-2012
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    48

    Re: Sum of 16 numbers out of 25, matching a number

    Hi.

    Thanks. It works great. Of course, it takes time to calculate, but so far, 5 solutions have been found with 1 hour.

    It helps much for the TV gameshow that I am designing for TF1, the French #1 channel and you can have the curiosity to see 1 min 30 of video of this gameshow's rehearsals in Paris here :

    https://www.box.com/s/rfiedxye3a9xbat7kp9t

    Have a nice day and thank you again.
    Best.
    Frederic

  10. #10
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Sum of 16 numbers out of 25, matching a number

    you are welcome Askalian and I really enjoyed while writing these codes



    Regards,
    DILIPandey
    <click on below * if this helps>

+ 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