What I'm trying to do here is see what the term value equals and go from there. If it's STD then I just need to add the days to the invoice date; If its BONM (begining of next month) I need it to add days to the invoice date and then reference the beginning of next month as the answer. If its EOM (end of month) i need it to add days to the invoice date and then reference the end of that current month. I've attached an image of the error that I'm getting. Tried dimming it in different ways but it's still not working.
Function OldMaturity(term As Range, invoicedate As Range, days As Range) As Date
Dim term As String
Dim invoicedate As Date
Dim days As Long
Dim val1 As Long
Dim val2 As Long
term = Termtype.Value
invoicedate = invoicedate.Value
days = days.Value
val1 = val1.Value
val2 = val2.Value
If term = "STD" Then
OldMaturity = invoicedate + days
Exit Function
End If
If term = "BONM" Then
val1 = invoicedate + days
val2 = DateAdd("m", 1, val1)
OldMaturity = DateSerial(Year(val2), Month(val2), 1)
Exit Function
End If
If term = "EOM" Then
val1 = invoicedate + days
OldMaturity = DateSerial(Year(val1), Month(val1) + 1, 0)
Exit Function
End If
End If
End Function
