Combination sum

Tuan Kriel

New Member
Joined
Sep 28, 2017
Messages
4
Hi, please help me with VBA code to identify all possible combinations & permutations from a list of values (subset) to sum to a Target value

I have two lists, lets call it list A & List B.
List A = {37.61,43.37,49.13,54.86,60.62}
List B = {0.76,2.74,5.49,8.23,10.97,13.72,16.46,19.51,22.25,24.99}
Let say my Target = 256.56
The Target value can be varied by user input

There are no constraints on List A (any value in the subset can be included, excluded, used once, used multiple times etc.)
The Values in List B can only be used once and will always be the last ellement

I need all possible combinations or permutations that equals or undershoot or overshoot the Target lets say by a limit of plus 3 or minus 3

My initial manual solution is: {37.61,43.37,49.13,54.86,60.62,10.97} = 256.56 (exact) (all elements from List A used once and one ellement from List B as the last ellement)
Possible other solutions is: {37.61,49.13,49.13,54.86,54.86,10.97} = 256.56 (exact)
{37.61,43.37,49.13,54.86,54.86,16.46} = 256.29 (Under - within limit)
{43.37,43.37,49.13,54.86,54.86,13.72} = 259.31 (over - within limit)

I'm certain that more solutions is possible but I'm hopefull that this will be enough to explain the outcome I'm looking for

To be added later.
Each ellement has a monetary value and the idea is to then sum the monetary values and determine which solution has the lowest value to identify the most economical option to use

In my workbook:
List A is in G60:G64 (Worksheet "Sheet21") named range "SpanLength168List"
List B is in J60:J69 (Worksheet "Sheet21") named range "Overhang168List"

List A represent span lengths used in centre pivot irrigators
List B represent the over hang section that makes up the end of the centre pivot irrigator

The unit of measure is in metric meter ie. 256.56m

 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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