Hi All!
I have a table as shown below, and I need a solution (Excel macro) how to find all combinations of Values that when summed equal to Sum Needed[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Names:
[/TD]
[TD]Values:
[/TD]
[/TR]
[TR]
[TD]Name1[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]Name2[/TD]
[TD]200[/TD]
[/TR]
[TR]
[TD]Name3[/TD]
[TD]300[/TD]
[/TR]
[TR]
[TD]Name4[/TD]
[TD]400[/TD]
[/TR]
[TR]
[TD]Name5[/TD]
[TD]500[/TD]
[/TR]
</tbody>[/TABLE]
Sum Needed: 1000
So, here 1000 can be reached in 3 ways:
1: Name2 + Name3 + Name5
2: Name1 + Name4 + Name5
3: Name1 + Name2 + Name3 + Name4
Value can be either used (full amount added) or not. So, only binary options (1 or 0) for each of values.
Also, in case no combination is found, a message should be provided.
How to do it?
Thanks!
I have a table as shown below, and I need a solution (Excel macro) how to find all combinations of Values that when summed equal to Sum Needed[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Names:
[/TD]
[TD]Values:
[/TD]
[/TR]
[TR]
[TD]Name1[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]Name2[/TD]
[TD]200[/TD]
[/TR]
[TR]
[TD]Name3[/TD]
[TD]300[/TD]
[/TR]
[TR]
[TD]Name4[/TD]
[TD]400[/TD]
[/TR]
[TR]
[TD]Name5[/TD]
[TD]500[/TD]
[/TR]
</tbody>[/TABLE]
Sum Needed: 1000
So, here 1000 can be reached in 3 ways:
1: Name2 + Name3 + Name5
2: Name1 + Name4 + Name5
3: Name1 + Name2 + Name3 + Name4
Value can be either used (full amount added) or not. So, only binary options (1 or 0) for each of values.
Also, in case no combination is found, a message should be provided.
How to do it?
Thanks!