Excel Formula

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,516
Office Version
  1. 2016
Platform
  1. Windows
Hello Friends,

Please have a look at the below table...
Formula required for Column E & F

Any help would be appreciated

Book2
ABCDEF
1Container SizeM3M3Required ContainersTotal Containers
2[20]30301 [20]1
3[40-STD]50501 [40-STD]1
4[40-HC]65651 [40-HC]1
5951 [40-HC] + 1 [20]2
6961 [40-HC] + 1 [40-STD]2
71151 [40-HC] + 1 [40-STD]2
81291 [40-HC] + 1 [40-STD]2
91302 [40-HC]2
101352 [40-HC] + 1 [20]3
111602 [40-HC] + 1 [20]3
121612 [40-HC] + 1 [40-STD]3
13
1420 feet container can take a load of max 30 M3
1540-STD feet container can take a load of max 50 M3
1640-HC feet container can take a load of max 65 M3
Sheet1


Regards,
Humayun
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi, with dozens of experiment I have come up with this...
Now the only problem remains is the part marked in red

I want the formula to go for the lower size containers when ever there is a possibility

hope anyone can help..

VBA Working.xlsm
ABCDEF
1Container SizeM3M3Required ContainersCorrect Answer
2[20]25251 [20]
3[40-STD]50301 [40-STD]
4[40-HC]65501 [40-STD]
5751 [40-HC] + 1 [20]1 [40-STD] + 1 [20] Reason: [40-STD] can lift 50 M3 & [20] can lift 25 M3 so why choose a higher container
6901 [40-HC] + 1 [20]
7951 [40-HC] + 1 [40-STD]
81011 [40-HC] + 1 [40-STD]
92053 [40-HC] + 1 [20]2 40 [HC] +1 [40-STD] + 1 [20] Reason: 2 [40-STD] will lift 130 M3 + 1 [40-HC] will lift 50 M3 + 1 [20] will lift 25 M3
102103 [40-HC] + 1 [20]
112153 [40-HC] + 1 [20]
122203 [40-HC] + 1 [20]
132253 [40-HC] + 1 [40-STD]
Container Breakup Formula (2)
Cell Formulas
RangeFormula
E2:E13E2=IF(D2<=$B$2,"1 "&$A$2,IF(D2<=$B$3,"1 "&$A$3,IF(D2<=$B$4,"1 "&$A$4,IF(AND(D2>$B$4,MOD(D2,$B$4)=0),(D2-MOD(D2,$B$4))/$B$4&" "&$A$4,IF(AND(D2>$B$4,MOD(D2,$B$4)<=$B$2),(D2-MOD(D2,$B$4))/$B$4&" "&$A$4&" + 1 "&$A$2,IF(AND(D2>$B$4,MOD(D2,$B$4)<=$B$3),(D2-MOD(D2,$B$4))/$B$4&" "&$A$4&" + 1 "&$A$3,ROUNDUP(D2/$B$4,0)&" "&$A$4))))))
 
Upvote 0
You could use Solver to minimize the excess capacity as below. In the example the total is 234 and solver arrived at a container inventory of 1 small, 3 medium, and 1 Large with a capacity of 240 (excess capacity = 240 -234 =6). Note that three large and a medium would have a capacity of 245 and an excess capacity of 11, so even though this configuration is fewer containers it isn't chosen because it has more excess capacity (11>6).

PQ 20210725.xlsx
ABCDE
1131Excess Capacity
22550656
3
4Target234
Sheet3
Cell Formulas
RangeFormula
E2E2=SUMPRODUCT(A1:C1,A2:C2)-E4


1627244743376.png
 
Upvote 0
Hi JGordon,

Sorry for coming back late on this....
I am not familiar with solver & also this would not serve the purpose as every time one has to run it

A formula is what I need

I am just posting the sample data again which would be easier to understand as compared to my initial post

Formula needed for Columns (D:F) to efficiently figure out how many containers would be required keeping in view that it would cost less
I have also added an example case in the sample data

Hope anyone can help

VBA Working.xlsm
ABCDEFGH
1SIZEM3Freight
2[20]25 $ 25
3[40 STD]55 $ 55
4[40 HC]65 $ 65
5
6 M3 [20] [40 STD][40 HC]Total Cost
7Case 1251-- $ 25
8Case 255-1- $ 55
9Case 365--1 $ 65
10Case 48011- $ 80
11Case 5145111 $ 145
12Case 61491-2 $ 155
13ExampleCase 7200121 $ 200 Efficient as compared to the next row because costing less
14ExampleCase 72001-3 $ 220 Not efficeint as compared to the above row because costing more
15Case 8255131 $ 255
Sheet5 (3)
Cell Formulas
RangeFormula
G7:G15G7=D7*$C$2+E7*$C$3+F7*$C$4



Regards,
Humayun
 
Upvote 0
Can be done with a VBA user defined function. It would be one heck of a complicated formula. The following code optimizes on cost then if there are more than one min cost option it selects the option with the min total number of containers.

If your 25, 55, 65 numbers change then change the Cost and Capacity array assignment lines in the code.

VBA Code:
Function OptimumCapacity(x As Double)
    Dim Capacity, Cost, Containers(1 To 1, 1 To 3), MinCost As Double, OrderCost As Double, Num As Long, i As Long, j As Long, k As Long
    Dim Quant As Long, OrderQuant As Long
    Capacity = Array(25, 55, 65)
    Cost = Array(25, 55, 65)
    MinCost = 9E+99
    Quant = x
    Do While Quant - Capacity(2) > Capacity(2) * 10
        Quant = Quant - Capacity(2)
        Num = Num + 1
    Loop
    For i = 0 To 10
        For j = 0 To 10
            For k = 0 To 10
                OrderCost = i * Cost(0) + j * Cost(1) + k * Cost(2)
                OrderQuant = i * Capacity(0) + j * Capacity(1) + k * Capacity(2)
                If OrderQuant >= Quant And OrderCost < MinCost Then
                    Containers(1, 1) = i
                    Containers(1, 2) = j
                    Containers(1, 3) = k + Num
                    MinCost = OrderCost
                End If
            Next
        Next
    Next
    OptimumCapacity = Containers
End Function

OptimizeCapacity.xlsm
ABCDEF
1M3255565CapacityExcess Capacity
251002520
3101002515
4151002510
520100255
625100250
7302005020
8352005015
9402005010
1045200505
1150200500
1255010550
1360001655
1465001650
1570300755
1675300750
1780110800
1885101905
1990101900
20954001005
211004001000
221052101050
231100201100
241152011150
251200111200
261255001250
271300021300
282000082420000
293000183930000
3070000210670000
311000001153100000
Sheet4
Cell Formulas
RangeFormula
B2:D31B2=OptimumCapacity(A2)
E2:E31E2=SUMPRODUCT(B2:D2,$B$1:$D$1)
F2:F31F2=E2-A2
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Hi JGordon,

Thanks for the UDF....
I tried but it is not giving me the correct results

Please let me know if I am doing anything wrong here

VBA Working.xlsm
ABCDEF
1M3255565CapacityExcess Capacity
25111145140
310111145135
415111145130
520111145125
625111145120
730222290260
835222290255
940222290250
1045222290245
1150222290240
12550000-55
13600000-60
14650000-65
1570333435365
1675333435360
178011114565
188511114560
199011114555
2095444580485
21100444580480
22105222290185
231100000-110
24115222290175
251200000-120
26125555725600
271300000-130
2820000000-2000
293000111145-2855
3070000000-7000
31100000000-10000
Sheet3
Cell Formulas
RangeFormula
B2:B31B2=OptimumCapacity(A2)
C2:C31C2=OptimumCapacity(A2)
D2:D31D2=OptimumCapacity(A2)
E2:E31E2=SUMPRODUCT(B2:D2,$B$1:$D$1)
F2:F31F2=E2-A2
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Needs to be entered into a one row by three column selection. So select B2:D2 then enter the formula =OptimumCapacity(A2) then enter by ctrl-shift-enter. Then drag the the three cell selection down.
 
Upvote 0
Needs to be entered into a one row by three column selection. So select B2:D2 then enter the formula =OptimumCapacity(A2) then enter by ctrl-shift-enter. Then drag the the three cell selection down.
Thanks... Got it worked... :)
I am still wondering how did you do that... I mean writing the UDF... hats off to you
I use VBA but at a very basic level....
Thanks Again

Few Questions:
1) Can the UDF be amended to look at the cell values for Cost & M3
2) What if I want to run this on my original sheet (this was a dummy sheet as you know) Like starting from row # 5 Column # 2.. Can you please guide me which part of the code needs to be changed..

Regards,
Humayun
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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