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
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