Excel Macro find all combinations of Values that equal to Sum Needed

exeluser1

New Member
Joined
Jun 18, 2017
Messages
6
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!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top