我已經足夠長練成這樣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