BringInRange

Public Function BringInRange(ByVal Value As Variant, ByVal MinValue As Variant, ByVal MaxValue As Variant)

Brings a value within the specified range. Make sure the MaxValue >= MinValue to prevent unexpected results.

Public Function CreateTime(pHour As Long, pMinute As Long) As Date
   Return TimeSerial(BringInRange(pHour, 0, 23), BringInRange(pMinute, 0, 59))
End Function

See also: