简体   繁体   中英

Excel: Decomposing numbers into sum of smaller numbers

This is a real world use case: I have a home gym with different weighting disks (1.25 kg, 5 kg, 10 kg etc).

I have created an excel spreadsheet that calculates the weight that i should lift per exercise, as an example:

第一次练习系列

My question is: how can I get Excel to automatically decompose each cell into the appropiate disks that I should put on the bar? This is limited by the number of disks per disks weight (I don't have an infinite amount of 1 kg disks)

Example:

On the first cell we have 55 (kg). Since I have 2 disks of 25 kg at home and multiple 5 kg disks, I would like Excel to output 25x2 + 5 .

15x2 + 10x2 + 2.5x2 would also work but it's much more inefficient, so what I'd like to get is the solution with the least amount of different disks.

Check out the MOD() and QUOTIENT() functions and set up a nested IF statement with the various weights you have available.

Eg, using your example with "weight" to be made with 25 and 5 kg weights, something like

=QUOTIENT(Weight,25) & " 25 kg weights" & IF(MOD(Weight,25)>0," and " & QUOTIENT(MOD(Weight,25),5) & " 5 kg weights ","") 

Here is a link with several solutions for your problem.
https://www.extendoffice.com/documents/excel/3557-excel-find-all-combinations-that-equal-given-sum.html
You can get there a pure Excel formula solution, Solver Add-In, or VBA. Comment if you need help adapting them.
Post your Excel file if you need more help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM