Hi there!
I am currently working on a project where I would like a macro to go through a "trial and error" process to find a best fit solution with a few constraints. I am new to vba and would love some help, even if it's just where to start.
The project I am working on has 4 unknowns counts (#A, #B, #C, #D), and I am given 4 prices for those items, the sum of (#A + #B + #C + #D = 4) and the total cost should be would be (#A*PriceA+#B*PriceB+#C*PriceC+#D*PriceD = 214.83). Column I ("Actual cost") is using columns A - D to calculate the total cost. I would like to have a macro go through all possible combinations of #A #B #C #D to get to the desired cost of 214.83 in this case, with the constraints that (#A + #B + #C + #D = 4) and that #A, #B, #C, #D are all whole numbers. (The answer is #A = 1, #B = 1, #C = 1, #D = 1).
Col A | Col B | Col C | Col D | Col E |Col F | Col G | Col H | Col I | Col J | Col K |
#A |#B | #C | #D | PriceA | PriceB | PriceC | PriceD |Actual Cost| Desired Cost | Needed Total of A B C D|
3 |1 | 0 | 0 | 24.57 |46.21 |55.04 | 89.01 | 119.2 | 214.83 | 4 |
Any help would be GREATLY appreciated!
Thank You!
I am currently working on a project where I would like a macro to go through a "trial and error" process to find a best fit solution with a few constraints. I am new to vba and would love some help, even if it's just where to start.
The project I am working on has 4 unknowns counts (#A, #B, #C, #D), and I am given 4 prices for those items, the sum of (#A + #B + #C + #D = 4) and the total cost should be would be (#A*PriceA+#B*PriceB+#C*PriceC+#D*PriceD = 214.83). Column I ("Actual cost") is using columns A - D to calculate the total cost. I would like to have a macro go through all possible combinations of #A #B #C #D to get to the desired cost of 214.83 in this case, with the constraints that (#A + #B + #C + #D = 4) and that #A, #B, #C, #D are all whole numbers. (The answer is #A = 1, #B = 1, #C = 1, #D = 1).
Col A | Col B | Col C | Col D | Col E |Col F | Col G | Col H | Col I | Col J | Col K |
#A |#B | #C | #D | PriceA | PriceB | PriceC | PriceD |Actual Cost| Desired Cost | Needed Total of A B C D|
3 |1 | 0 | 0 | 24.57 |46.21 |55.04 | 89.01 | 119.2 | 214.83 | 4 |
Any help would be GREATLY appreciated!
Thank You!