I've plenty long excel formula like this
IF(ISNUMBER(E6),IF(E6<standard_hour,0,IF(((E6-standard_hour)*24*60)>90,2,CEILING(((E6-standard_hour)*24*60)/30*0.5,0.5))),VLOOKUP(E6,Refer,2,FALSE))
Because I use this formula a lot in spreadsheet, I decide to make a custom function for it. This is the function
Function morning_check(start_hour)
Dim sheet As Worksheet
Set sheet = ActiveWorkbook.Sheets("Setup")
If WorksheetFunction.IsNumber(start_hour) Then
If start_hour < sheet.Range("E1").Value Then
morning_check = 0
Else
If ((start_hour - sheet.Range("E1").Value) * 24 * 60 > 90) Then
morning_check = 2
Else
morning_check = Application.WorksheetFunction.Ceiling(((start_hour - sheet.Range("E1")) * 24 * 60) / 30 * 0.5, 0.5)
End If
End If
Else
morning_check = Application.WorksheetFunction.VLookup(start_hour, sheet.Range("Refer"), 2, False)
End If
End Function
The input of this function could be string (example : "TS") or time (example : 07:00)
Using String as Input, this function work correctly, but when I using time it just throw #Value!