BrotherDude
Board Regular
- Joined
- Sep 11, 2013
- Messages
- 50
Hello all,
I am trying to create a function that would allow me to select a date cell and add a certain amount of days to it until it is larger than the current date. I keep crashing excle with the function below any suggestions? Seems like I am declaring the variables incorrectly.
Public Function NextDueDate(StartDate As Range, NumberDays As Integer) As Date
On Error GoTo Err_Handler
Dim DueDate As Date
Dim TodaysDate As Date
TodaysDate = Date
If IsNull(StartDate) Or IsNull(NumberDays) < 0 Then
NextDueDate = Null
GoTo Exit_Proc
End If
Do Until DueDate > TodaysDate
DueDate = StartDate + NumberDays
Loop
NextDueDate = DueDate
Exit_Proc:
On Error Resume Next
Exit Function
Err_Handler:
MsgBox Err.Number & " " & Err.Description, vbCritical, _
"NextDueDate()"
NextDueDate = Null
Resume Exit_Proc
End Function
Any help is much appreciated
-Jeff
I am trying to create a function that would allow me to select a date cell and add a certain amount of days to it until it is larger than the current date. I keep crashing excle with the function below any suggestions? Seems like I am declaring the variables incorrectly.
Public Function NextDueDate(StartDate As Range, NumberDays As Integer) As Date
On Error GoTo Err_Handler
Dim DueDate As Date
Dim TodaysDate As Date
TodaysDate = Date
If IsNull(StartDate) Or IsNull(NumberDays) < 0 Then
NextDueDate = Null
GoTo Exit_Proc
End If
Do Until DueDate > TodaysDate
DueDate = StartDate + NumberDays
Loop
NextDueDate = DueDate
Exit_Proc:
On Error Resume Next
Exit Function
Err_Handler:
MsgBox Err.Number & " " & Err.Description, vbCritical, _
"NextDueDate()"
NextDueDate = Null
Resume Exit_Proc
End Function
Any help is much appreciated
-Jeff