我正在编写一个返回奖励值的函数
我试图通过小时作为输入
Function CalculateBonus(workedhours As Variant) As Variant
CalculateBonus= TimeValue(workedhours) / TimeValue("30:00:00")
End Function
通过30:00时,应返回1;通过45:00时,应返回1.5
答案 0 :(得分:0)
如果您以“ HH:mm”格式将时间作为字符串传递,则可以使用以下方式:
Function CalculateBonus(workedhours As String) As Double
Dim hours As Integer, minutes As Integer
hours = Left(workedhours, InStr(1, workedhours, ":") - 1)
minutes = Right(workedhours, Len(workedhours) - InStr(1, workedhours, ":"))
CalculateBonus = (hours * 60 + minutes) / 1800
End Function