+ Reply to Thread
Results 1 to 5 of 5

Combination of Numbers that equal a certain Sum

  1. #1
    Registered User
    Join Date
    08-25-2012
    Location
    LA, USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Combination of Numbers that equal a certain Sum

    Hi everyone, I have an interesting problem which I still can't find a solution to even in other forums. Hope someone can help. Anyway, I'd like to generate a list that exhausts all possible combinations for a given sum with a given number of columns. For example, I would like to know all the possible combinations by which I can arrive at 50 using 7 columns.

    1st combination
    Col 1: 49
    Col 2: 1

    2nd combination
    Col 1: 49
    Col 2: 0
    Col 3: 1

    3rd combination
    Col 1: 49
    Col 2: 0
    Col 3: 0
    Col 4: 1

    (...until col 7)

    I'd also like to have:
    Col 1: 48
    Col 2: 1
    Col 3: 1
    Col 4: 0
    col 5: 0
    col 6: 0
    col 7: 0

    Col 1: 48
    Col 2: 2
    Col 3: 0
    Col 4: 0
    col 5: 0
    col 6: 0
    col 7: 0

    and so on.... (Hopefully my example is clear cause im having problems pasting a table here)

    I do hope that if anyone comes up with a code, it will be generic (i.e. not just for sum of 50 or column of 7). I actually wish to use this even for sum of 100. Thanks for the help, it will be greatly appreciated
    Last edited by darkwinged; 08-25-2012 at 12:46 AM.

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Combination of Numbers that equal a certain Sum

    Hello darkwinged,

    Maybe the attached WorkBook will give you a Start.

    Please also see the "Please consider notes at the bottom of this post.
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Combination of Numbers that equal a certain Sum

    Hello darkwinged,

    Simple formulas in excel won't allow you to get all the combinations, but it might be the only way to go.

    If you want to exhaust all the possible combinations by which you can arrive at say only 37 using 7 columns, would require 94,931,877,133 Cells using 13,561,696,733 Rows.

    Can you imagine how many Cells/Rows the number 50 or 100 would require?

    I don't think Spreadsheets are that big yet, Let alone looking through that many Cells/Rows to find what you may like.

    Anyway, Good Luck - Maybe I am wrong - And just maybe some Forum Guru can prove it possible.

  4. #4
    Registered User
    Join Date
    08-25-2012
    Location
    LA, USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Combination of Numbers that equal a certain Sum

    Thanks for the response again sir Winon, I think you're right I totally forgot about the limits of excel. But how about if I just want to do a VBA program for the same problem but now I will only account for combinations that use multiples of 5.

    Example:
    Col1 : 45
    Col2: 5
    Col3: 0
    col4: 0
    col5: 0
    col6: 0
    col7: 0

    Col1 : 45
    Col2: 0
    Col3: 5
    col4: 0
    col5: 0
    col6: 0
    col7: 0

    (until col 7 =5)

    Col1 : 35
    Col2: 5
    Col3: 5
    col4: 5
    col5: 0
    col6: 0
    col7: 0

    (so on.. )

    perhaps until:

    Col1 : 5
    Col2: 0
    Col3: 0
    col4: 0
    col5: 0
    col6: 0
    col7: 45

    I think this is more feasible. But I really am having a tough time crafting the formula for this. Hope someone can assist. Thank you very much!

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Combination of Numbers that equal a certain Sum

    Hello darkwinged,

    That would still have to cater for 3125 possible combinations, and quite frankly, I do not know how to Code for that.

    Sorry, but I surrender. Would love to see it done though.

+ 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