試試!
Sub XL()
Dim E As Range
With Sheets("Sheet1") 'Sheet1 工作表名稱
For Each E In .Range("A1", [A65536].End(xlUp))
If TimeValue(E) > TimeValue("00:00:01") And TimeValue(E) < TimeValue("07:30:00") Then
E.Offset(, 1) = (Format(DateValue(E) - 1, "mm/dd")) & " 夜班"
ElseIf TimeValue(E) > TimeValue("07:31:00") And TimeValue(E) < TimeValue("19:30:00") Then
E.Offset(, 1) = (Format(E, "mm/dd")) & " 日班"
Else
E.Offset(, 1) = (Format(E, "mm/dd")) & " 夜班"
End If
Next
End With
End Sub作者: tku0216 時間: 2014-12-29 23:16
改了[紅字]部分,再驗證看看是不是符合需求?!
Sub XL()
Dim E As Range
With Sheets("Sheet1") 'Sheet1 工作表名稱
For Each E In .Range("A1", [A65536].End(xlUp))
If TimeValue(E) >= TimeValue("00:00:01") And TimeValue(E) <= TimeValue("07:30:00") Then
E.Offset(, 1) = (Format(DateValue(E) - 1, "mm/dd")) & " 夜班"
ElseIf TimeValue(E) >= TimeValue("07:30:01") And TimeValue(E) <= TimeValue("19:30:00") Then
E.Offset(, 1) = (Format(E, "mm/dd")) & " 日班"
Else
E.Offset(, 1) = (Format(E, "mm/dd")) & " 夜班"
End If
Next
End With
End Sub