Months of Coverage

spcalan

Well-known Member
Joined
Jun 4, 2008
Messages
1,247
Today I use this function to calculate months of coverage
=coverage(Cell that holds inventory, range of cells that have the monthly forecast)
=coverage(F7,G5:I5)

I want to use a function that does the same thing, but with value in the function such as :

=coverage(1000,500,250,150,50)

Thoughts ?

Function coverage(inventory, forecast)
Application.Volatile
For Each c In forecast
inventory = inventory - c.Value
Select Case inventory
Case Is > 0
coverage = coverage + 1
Case Is = 0
coverage = coverage + 1
Exit Function
Case Is < 0
If c.Value <> 0 Then
coverage = coverage + (1 - (Abs(inventory) / c.Value))
Else
coverage = coverage
End If
Exit Function
End Select
Next c
End Function
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this:

Code:
Function coverage(inventory, ParamArray forecast() As Variant)
Application.Volatile
Dim c As Long
For c = LBound(forecast) To UBound(forecast)
    inventory = inventory - forecast(c)
    Select Case inventory
    Case Is > 0
        coverage = coverage + 1
    Case Is = 0
        coverage = coverage + 1
        Exit Function
    Case Is < 0
        If c <> 0 Then
        coverage = coverage + (1 - (Abs(inventory) / forecast(c)))
    Else
        coverage = coverage
    End If
        Exit Function
    End Select
Next c
End Function
 
Upvote 0
Hi Spcalan,
so your function would have 1 input for "inventory" and after that multiple for the monthly forecast? Is there some kind of logic to the number of cells you'd want to use for the forecast? And are they single cells or do you want multiple ranges (with each multiple cells)?
Cheers,
Koen
 
Upvote 0
Try this:

Code:
Function coverage(inventory, ParamArray forecast() As Variant)
Application.Volatile
Dim c As Long
For c = LBound(forecast) To UBound(forecast)
    inventory = inventory - forecast(c)
    Select Case inventory
    Case Is > 0
        coverage = coverage + 1
    Case Is = 0
        coverage = coverage + 1
        Exit Function
    Case Is < 0
        If c <> 0 Then
        coverage = coverage + (1 - (Abs(inventory) / forecast(c)))
    Else
        coverage = coverage
    End If
        Exit Function
    End Select
Next c
End Function


Thanks !
works perfect .
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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