Olá pessoal
Tenho um problema em uma função que fiz. Sempre retorna erro "#VALOR!".
O código da função é:
Function CDI(DataInicial As Date, DataFinal As Date, PercentualCDI As Long) As Long
Dim a, b As Date
Dim diini As Integer, difin As Integer
Dim s, e, taxas, Cell As Range
With Planilha3.Range("E1:E10000")
s = Range(.Find(DataInicial, LookIn:=xlValues).Address).Row
e = Range(.Find(DataFinal, LookIn:=xlValues).Address).Row - 1
End With
Set taxas = Planilha3.Range(Cells(diini, 6), Cells(difin, 6))
CDI = 1
For Each Cell In taxas
CDI = CDI * (Cell.Value / 100 * PercentualCDI + 1)
Next Cell
End Function
Para testar o cálulo executado eu criei uma sub que está funcionando bem. Mas gostaria de ter a mesma funcionalidade em uma função
A Sub que fiz é essa:
Sub CDI1()
Dim s, e, taxas As Range
Dim DtIni, DtFim As Date
Dim CDI, percuntualCDI As Long
DtIni = Range("a1").Value
DtFim = Range("a2").Value
PercentualCDI = Range("a3")
With Planilha3.Range("E1:E10000")
s = Range(.Find(DtIni, LookIn:=xlValues).Address).Row
e = Range(.Find(DtFim, LookIn:=xlValues).Address).Row - 1
End With
Set taxas = Planilha3.Range(Cells(s, 6), Cells(e, 6))
CDI = 1
For Each Cell In taxas
CDI = CDI * (Cell.Value / 100 * PercentualCDI + 1)
Next Cell
Range("A4") = CDI
End Sub
Eu acho que o erro na FUNÇÃO está relacionado a declaração das variáveis...mas não sei como resolver esse erro.
Alguém pode me ajudar?
obrigado
Helder