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?
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?
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.
Originally Posted by shg
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.
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.
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
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks