Days supply in excel - formula

sasils

New Member
Joined
Jun 3, 2017
Messages
24
Hi,

Need advise from the experts in this forum. Data is below

W1W2W3W4W5W6W7W8W9W10
Forecast10202010102010201010
Closing stock40204020202010401010
Week supply2131.511.50.5

<colgroup><col><col span="10"></colgroup><tbody>
</tbody>

I would like to get a automatic calculation formulation for Week supply. For example. In Week 1 Week supply is 2 because of Week 1 closing stock can cover forecast for week 2 and week 3 (20+20) - 40 = 0, therefore it is 2.

However in Week 5 Week supply is 1.5 week because week 6 forecast is 10 and week 7 forecast is 20, closing stock in week 5 is 20, therefore week supply base on closing stock week 5 going forward is 1.5.

Hope this explains.

Cheers

Sasils
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

kvsrinivasamurthy

Well-known Member
Joined
Nov 6, 2013
Messages
690
UDF means user defined function. Function which we have to code. After coding it can be used like other function.
 

kvsrinivasamurthy

Well-known Member
Joined
Nov 6, 2013
Messages
690
Data is in A1:K3

Formula in B4 then drag across
=GetWeeks(B3,C$2:$K$2)

Code for UDF GetWeeks

Code:
Function GetWeeks(ClosingStock As Long, WeekRng As Range)


Dim T As Long


For T = 1 To WeekRng.Cells.Count


    If ClosingStock > WeekRng.Cells(1, T) Then
    GetWeeks = T
    ClosingStock = ClosingStock - WeekRng.Cells(1, T)
    
    ElseIf ClosingStock = WeekRng.Cells(1, T) Then
    GetWeeks = T
    Exit For
    
    Else
    GetWeeks = GetWeeks + Round(ClosingStock / WeekRng.Cells(1, T), 2)
    Exit For
    End If


Next T


End Function

Open tab Developer --> Visual Basic
IN VIsual Basic window

Insert --> Module

Now Paste the given code to module

Close the VB window

UDF is available in the function list like other functions.
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,129,361
Messages
5,635,812
Members
416,884
Latest member
leeshjay

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
Top