Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2008

Tip: Looking for answers? Try searching our database.

How can I make a calculator in Excel for the following items...?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nLinked - 29 Jan 2008 14:54 GMT
Lets say I have the following weight plates for my home gym:

4x 10 kg
6x 2 kg
8x 1kg
2x 20 kg

I want to make a calculator in Excel where I say I want a total of 12 kg
(for example), and it automatically assigns the available plates for each
side of my weight lifting bar (so 6 kg per side).

It has to consider that I only have those available plates. And if it can't
find a perfect match, it has to find the nearest weight.

Any ways this can be done in Excel?

Yes, I know it's easy so work out the weights on your own but I have a lot
more weights than that and it would be quite helpful to plan my
periodization routine more quickly. I'm sure it could come in helpful for
others too.
Gary''s Student - 29 Jan 2008 15:40 GMT
Start by listing the individual weights in a column:
10
10
10
2
2
2
2
2
2
1
1
1
1
1
1
1
1
20
20

Then you can use Solver to pick a subset that sums to a desired total.  See:

http://www.tushar-mehta.com/excel/templates/match_values/index.html#Solver_Template

Signature

Gary''s Student - gsnu200766

> Lets say I have the following weight plates for my home gym:
>
[quoted text clipped - 16 lines]
> periodization routine more quickly. I'm sure it could come in helpful for
> others too.
nLinked - 29 Jan 2008 16:00 GMT
Thanks that does work! All I need to specify is half the weight that I'll
need, let it solve it, and then I know I need these plates on one side, and
the same amount on the other. I'm going to look deeper into Solver.

Many thanks!

> Start by listing the individual weights in a column:
> 10
[quoted text clipped - 44 lines]
>> periodization routine more quickly. I'm sure it could come in helpful for
>> others too.
Dana DeLouis - 30 Jan 2008 05:03 GMT
> I'm going to look deeper into Solver.

Just something to keep in mind for this particular type of problem.

To reduce the size of the Solver problem, I might use half the weights also.

wgts = {1, 1, 1, 1, 2, 2, 2, 10, 10, 20}

Note that many totals have more than 1 solution.  For example, if I want 14
(total weight 28), then there are 3 solutions that total 14:

{14, {2, 2, 10}},
{14, {1, 1, 2, 10}},
{14, {1, 1, 1, 1, 10}}

My guess is that one would prefer the "Least" amount of weights to add.
If this is a requirement, then Solver becomes a little harder to use as it
requires mulitple loops.
For small problems like this, finding all the subsets of the above list
might be another option.  For each total, pick the one with the least amout
of weights.

For example, for 20, pick
{10, 10},
instead of
{1, 1, 1, 1, 2, 2, 2, 10}

Note that with the numbers {1, 1, 1, 1, 2, 2, 2} summing to 10, then all
numbers between 1 and 50 can be included.
Signature

Dana DeLouis

> Thanks that does work! All I need to specify is half the weight that I'll
> need, let it solve it, and then I know I need these plates on one side,
[quoted text clipped - 52 lines]
>>> for
>>> others too.
Dave D-C - 30 Jan 2008 05:10 GMT
The old "find the combination" problem.
Best done with recursion.

Say A1:E1 is Kg 20 10 2 1
and A2:E2 is Num 1 2 3 4
(1/2 the weights)
Then the following will find a combination
for 1/2 of the total. E.g. 15 gives
15 b 1 2 1 (which is 10+2*2+1=15)
in A4:E4

Option Explicit
Dim zTarget%, zBest%

Sub Main()
 Rows(3).Resize(65534).Delete
 zTarget = InputBox("Target?")
 Call GetCombo(0, 2) ' kg, col
End Sub

Sub GetCombo(pKg&, pCol%)
 ' get weight combination routine
 Dim iCol%, iNum%, CellSav
 ' see if this is better
 If Abs(pKg - zTarget) < Abs(zBest - zTarget) Then
   Rows(3).Copy Rows(4) ' best so far
   zBest = pKg
   Cells(4, 1) = pKg
 End If
 ' go thru this column's weights
 For iCol = pCol To 5
   For iNum = Cells(2, iCol) To 1 Step -1
     CellSav = Cells(3, iCol)
     Cells(3, iCol) = iNum
     ' recursive call to next weights
     Call GetCombo(pKg + Cells(1, iCol) * iNum, iCol + 1)
     Cells(3, iCol) = CellSav
   Next iNum
 Next iCol
End Sub ' Dave D-C

There is a relatively easy speedup if you have many weights.

>Lets say I have the following weight plates for my home gym:
>4x 10 kg
[quoted text clipped - 14 lines]
>periodization routine more quickly. I'm sure it could come in helpful for
>others too.
nLinked - 30 Jan 2008 16:53 GMT
Thank you for the code. I have tried pasting that into a macro and assigning
it to a button in Excel but I'm getting various errors. How can I get it to
work?

And in reply to Dana's reply, providing an answer  to select the least
amounts of weights would be the best choice, yes. Unfortunately I have very
little programming knowledge but really want to get this solved.

Thanks.

> The old "find the combination" problem.
> Best done with recursion.
[quoted text clipped - 58 lines]
>>periodization routine more quickly. I'm sure it could come in helpful for
>>others too.
nLinked - 30 Jan 2008 16:59 GMT
Hi Dave,

I have just got this working!

Thank you very much!

> The old "find the combination" problem.
> Best done with recursion.
[quoted text clipped - 58 lines]
>>periodization routine more quickly. I'm sure it could come in helpful for
>>others too.
nLinked - 30 Jan 2008 17:16 GMT
Just to clarify, where you say:

>Say A1:E1 is Kg 20 10 2 1
> and A2:E2 is Num 1 2 3 4
> (1/2 the weights)

Do you mean the values in the Num row should be half the quantity of each
weight that I own? So if I have two 20kg weights, I should put 1 in the Num
row?

Thanks.

> The old "find the combination" problem.
> Best done with recursion.
[quoted text clipped - 58 lines]
>>periodization routine more quickly. I'm sure it could come in helpful for
>>others too.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.