[VBA] Subset of given numbers that is closest to a target sum(but exceeds the target number)

Insu

New Member
Joined
Sep 16, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello, I have been struggling finding subset(combination) of given nubmers that is closest to a target sum.(but exceeds the target number)
Please see the example below.

Candidates of numbers(which varies everytime) : {1.8 , 1.9 , 1.7 , 9.5 , 9.6 , 9.4 , 9.5 , 9.6 , 18.7 , 18.7 , 18.6 , 17.7}
Target sum(given sum) : 53
I want to find out combination of numbers which is closest to 53 (but exceed 53) in Excel.


I have been trying to find a vba algorithm to solve this kind of problem, but couldn't find one which exactly fit into mine.(most of them were in C++, Python, Java..)
I would really appreciate it if you could help me with this matter.

Thank you so much, in advance !
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Where to store the numbers list? somewhere in worksheet or inside VBA code?
What max/min of number of candidates possibly could be (Its 12 in this sample)?
 
Upvote 0
Thanks for the reply.

the numbers list will be stored in worksheet of Excel. (in the cells vertically)
the minimum number of candidates are around 10 and the maximum limit will be probably around 50s.

Please let me know if you need any further information.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,390
Members
448,957
Latest member
Hat4Life

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