+ Reply to Thread
Results 1 to 6 of 6

Find combination of numbers that when added, equal a known value.

  1. #1
    Registered User
    Join Date
    01-23-2013
    Location
    phoenix, arizona
    MS-Off Ver
    Excel 2012
    Posts
    71

    Find combination of numbers that when added, equal a known value.

    Suppose I have something like:

    A1 = 500
    A2 = 650
    A3 = 725
    A4 = 18
    A5 = 1000

    A10 = 1518

    A10 is the sum of A1+A4+A5. How would I get Excel to tell me what combination of numbers in a particular range equal a known value?

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,844

    Re: Find combination of numbers that when added, equal a known value.

    Standard "first approach" that I see mentioned is to use Solver.

    1) Add a column of 1's and 0's in column B
    2) Add a sumproduct function =SUMPRODUCT(A1:A5,B1:B5)
    3) I like to subtract the desired total from the sumproduct function =A10-B10
    4) Call Solver and tell it to
    a) set Target cell -- this last cell
    b) to a value of -- 0
    c) by changing -- the column of 1's and 0's B1:B5
    d) Add constraint that B1:B5 are binary (bin).
    5) Tell it to Solve and it should find solution (if there is one to be found).

    Note that, as your ranges become larger, it will take longer to find the solution. For a range of 5 it should find the solution fairly quickly. I don't know if you will need this for a larger range or not.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    01-23-2013
    Location
    phoenix, arizona
    MS-Off Ver
    Excel 2012
    Posts
    71

    Re: Find combination of numbers that when added, equal a known value.

    I've used Solver as well, but yeah, sometimes I have up to 50 cells, so I was hoping somebody might have an algorithm lying around somewhere.

  4. #4
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Find combination of numbers that when added, equal a known value.

    As there are many degrees of freedom in this question, I can only see one method of solving (via a PC) and that is by trial and error aka brute force try everything and hope it sticks - which in this case involves:

    Finding ALL combinations of possible solutions and testing them out. You mentioned 50 cells, which will mean 1,125,899,906,842,620 different combinations - which if your computer supports it - will involves
    1) Generating all possible combinations of 50C1, 50C2, 50C3, 50C4... 50C50.
    2) Testing each of the combinations listed in 1.

    which leads me to think that you're better off testing it by eye and logic.

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

    Re: Find combination of numbers that when added, equal a known value.

    This can be a very numerically-intensive exercise, depending on the number of values that you start with. Here's a thread from some time ago which discusses various approaches and offers a number of solutions:

    https://groups.google.com/forum/?hl=...sc/YaCpKgfIxBQ

    Hope this helps.

    Pete

  6. #6
    Registered User
    Join Date
    01-23-2013
    Location
    phoenix, arizona
    MS-Off Ver
    Excel 2012
    Posts
    71

    Re: Find combination of numbers that when added, equal a known value.

    Thanks Pete! That's about what I was looking for.

    Thanks as well quekbc. Brute forcing was never a consideration (hence my reluctance to use Solver). More to the point, I wanted something I could learn from (basically how to design Solver). This was enlightening.

+ 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. Replies: 8
    Last Post: 09-10-2015, 03:43 PM
  2. Need Formule to find best combination of numbers...
    By Shreyalmuri in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-09-2013, 07:46 AM
  3. Combination of Numbers that equal a certain Sum
    By darkwinged in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-27-2012, 02:30 AM
  4. how to i find combination 6 of 8 numbers in lotto 6/45
    By bemax38 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-02-2012, 04:47 AM
  5. [SOLVED] Find a sum of a combination of cells to equal a value
    By Hervinder in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2006, 11:40 AM
  6. Find the combination of numbers that when added equal a reqired total??
    By Handsy11 in forum Excel Formulas & Functions
    Replies: 41
    Last Post: 09-06-2005, 03:05 PM
  7. Find combinations of numbers to equal a value
    By jubu in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-18-2005, 09:06 AM

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