I have a function that is supposed to take a time, ex, 05:00:00 and check it with the current time (and an optional another time), and if the time in the argument has already passed, it's supposed to return the same time, but the next day.
For example, if tm = 05:00:00 and now = 2018-08-14 12:00:00, then the function should return 2018-08-15 05:00:00, but if the time hasn't passed, ex. tm = 19:00 i.e., now < tm, then it should return 2018-08-14 19:00.
My function is (in a separate module):
'Day Adjustment
Sub DayAdjust(tm As Double, Optional tm2 As Double = 0)
If tm2 = 0 Then
tm2 = DayAdjust(tm)
End If
If (Date + tm) < Now() Or (Date + tm) < tm2 Then
tm = (Date + 1 + tm)
End If
MsgBox tm
DayAdjust = tm
End Sub
The code that calls the function is:
Dim schStart, schEnd As Double
schStart = Range("cdh_schStart").Value
schStartTime = DayAdjust(CDbl(schStart))
schEnd = Range("cdh_schEnd").Value
schEndTime = DayAdjust(schEnd, schStart)
The cell cdh_schStart contains the value 05:00:00, and cdh_schEnd has 08:00:00 with the present system time set to 2018-08-14 18:30:00.
On the 3rd line, schStartTime = DayAdjust(CDbl(schStart)), I get the error:
Compile Error:
Expected Function or Variable
I need some help figuring out why this happens and how to fix it.
DayAdjustas a Sub not a Function.tm2or pass 0 by mistake.