gravanoc
Active Member
- Joined
- Oct 20, 2015
- Messages
- 348
- Office Version
- 365
- Platform
- Windows
- Mobile
Imagine you have a list of numbers: 5, 15, 20, 10, 25, 30, 10. From that list you can choose how many of those numbers to add up so that they are the highest possible sum without exceeding a certain limit. For example, in situation #1 you are able to add 3 of them (no more, no less) so that they come out at a maximum sum that is less than 58. You couldn't choose 30 + 25 + 5, since the sum exceeds 58. 30 + 25 = 55 would be wrong because you only used 2 numbers. Your best choice would be 20 + 25 + 10 = 55. Situation #2 you are given the same list of numbers, but must add 4 of them together so that they do not exceed 71. That's the general pattern.
The list of numbers generated is random, the number of numbers to be added together is random, and the limit is random. How would I best go about determining a generalized way in either VBA or formulas to always return the best sum, or return Null if no such sum exists?
Thank you.
The list of numbers generated is random, the number of numbers to be added together is random, and the limit is random. How would I best go about determining a generalized way in either VBA or formulas to always return the best sum, or return Null if no such sum exists?
Thank you.