View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove Harlan Grove is offline
external usenet poster
 
Posts: 733
Default Find numbers in an array that sum to a certain number

tommydancer wrote...
How do I get Excel to search an array of numbers and find only those numbers
that sum to a certain total? Which of the following numbers (3,5,7,14,20)
total 22? Answer: 3, 5, and 14 total 22


This is a classic programming problem. The answer is that there's no
guaranteed way to find the solution to this problem that doesn't
require iterating through all possible subsets of the individual
numbers. And if there are N individual numbers, there are 2^N-1
nontrivial subsets. For N-5, that means only checking 31 subsets of the
numbers. For N=20, there's over a million. For N=100, you'd need months
of uninterrupted supercomputer time.

Actually, that overstates the problem a bit, but only a bit. Heuristics
can be applied to limit the subsets, but that only eliminates a few
orders of magnitude.

Use Google Groups advanced search to find previous responses to this
sort of question. You could use the search words SUMPRODUCT and SOLVER
as well as the search phrase "sum to" to find solutions that'd give one
possible combination. If you want all such combinations, you'll need to
use VBA, and it could take a LONG time, long as in hours. Solutions
that'd require days or longer would exceed system resources long before
that.