我已经足够长练成这样VBA函数在Excel中返回值
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))
公式,因为我在电子表格中使用这个公式了很多,我决定做一个自定义的功能吧。这是函数
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
此函数的输入可以是字符串(例如:“TS”)或时间(例如:07:00)
使用字符串作为输入时,该功能正常工作,但当我使用时间只是抛出#Value!
哪一行是错误的来源?如果您选择调试,Excel应该突出显示它。 –
它的亮点第一行 – l1th1um