Pergunta

I am having trouble with the following line of code.

'payFreq is input of type "Long"
Dim DF As Variant
'discFact here is input of type "Range"
DF = discFact.Value

Dim Payment_pay() As Double
ReDim Payment_pay(1 To UBound(DF))

Dim i As Long
'Fill with zeros
For i = 1 To UBound(Payment_pay)
 Payment_pay(i) = 0
Next i

Dim Prev_date As Date
Dim Next_date As Date

For i = 1 To UBound(Payment_pay)
 Prev_date = makeDate((i - payFreq_pay) & "M")
 Next_date = makeDate(i & "M")
Next i

'Continuation of code...

The makeDate function is basically

Function makeDate(Term As String) As Date
 ...
End Function

Trying to output the variable Prev_date or Next_date won't work! However, interchanging the upper loop bound ( UBound(Payment_pay ) to e.g. 6, will give the expected return value (a correct date...). It seems something is wrong with the looping iterator "i".

Help is much appreciated!

Thanks in advance, Niklas

Foi útil?

Solução

Try this

For i = 1 To UBound(Payment_pay)
 Prev_date = makeDate(format(i - payFreq_pay) & "M")
 Next_date = makeDate(format(i) & "M")
Next i
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top