How do I translate this macro to an excell formula?

BRZ_ICE

New Member
Joined
Jan 7, 2014
Messages
2
I am facing a lot of issues with a macro, and would like to ask your help to write a formula to replace the macro bellow:

Public Function f_Cobertura(Demanda, Estoque) As Single
Dim J As Single, k As Integer, l As Single, M As Integer, n As Integer
Dim R As Range

J = 0 'cobertura
k = I + 1 'mes de venda
l = Estoque 'estoque

'identifica o fim do horizonte de venda
Set R = Demanda
n = R.Columns.Count

Do While l > 0 And k <= R.Columns.Count

If l - R.Cells(1, J + 1) >= 0 Then
J = J + 1
l = l - R.Cells(1, J)
k = k + 1
Else
J = J + l / R.Cells(1, J + 1)
l = l - R.Cells(1, Int(J) + 1)
End If
If k > n Then Exit Do
Loop

If k > n Then J = 99

f_Cobertura = J

End Function
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Missing point: Just to clarify, this macro was created to calculate inventory forward coverage.
 
Upvote 0

Forum statistics

Threads
1,216,496
Messages
6,130,984
Members
449,612
Latest member
geniusufo007

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