=IF((effDate)-curDate>0,0,IF(curDate-(effDate)+1>nDays,0,nSpend/4))+IF((effDate+365/4*1)-curDate>0,0,IF(curDate-(effDate+365/$4*1)+1>nDays,0,nSpend/4))+IF((effDate+365/4*2)-curDate>0,0,IF(curDate-(effDate+365/4*2)+1>nDays,0,nSpend/4))+IF((effDate+365/4*3)-curDate>0,0,IF(curDate-(effDate+365/4*3)+1>nDays,0,nSpend/4))
effDate: 1/1/2017 (as value)
curDate: 1/31/2017 (as value)
nSpend: 1600
nDays: 60
Correct answer: 400
Above is a long formula I'm trying to covert to VBA code. The way I've been trying to do it is long and I tried breaking it up into smaller functions, but it's not giving me the right answer. My VBA skills are very beginner so I'm not sure what else to try. I keep getting the wrong answer or no answer at all.
This is what I've been trying:
If effdate - curdate > 0 Then
val1 = 0
Exit Function
End If
If curdate - effDate + 1 > nDays Then
val1 = 0
Else
val1 = nSpend / 4
End If
If (effDate + (365 / 4)) - curdate > 0 Then
val2 = 0
Exit Function
End If
If curdate - (effDate + (365 / 4)) + 1 > nDays Then
val2 = 0
Else
val2 = nSpend / 4
End If
If effDate + (365 / (4 * 2)) - curdate > 0 Then
val3 = 0
Exit Function
End If
If curdate - (effDate + (365 / (4 * 2))) + 1 > nDays Then
val3 = 0
Else
val3 = nSpend / 4
End If
If effDate + (365 / (4 * 3)) - curdate > 0 Then
val4 = 0
Exit Function
End If
If curdate - (effDate + (365 / (4 * 3))) + 1 > nDays Then
val4 = 0
Else
val4 = nSpend / 4
End If
End If
APFcst = val1 + val2 + val3 + val4
End Function
I dimmed everything correctly, it's the actual conversion that I have problems with. I would appreciate the help! This is also a huge learning stretch for me since I just started learning VBA coding. Thank you!
