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
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