'条件好像有问题,星期五为什么有上午,自己测试一下
Option Explicit
Sub test()
Dim mark, i, t, arr
arr = Range("j2:l" & Cells(Rows.Count, "j").End(xlUp).Row)
mark = "一二三四五六日"
For i = 1 To UBound(arr, 1)
t = InStr(mark, Right(arr(i, 2), 1))
Select Case t
Case 1
arr(i, 1) = IIf(CDate(arr(i, 1)) >= #9:00:00 AM# And _
CDate(arr(i, 1)) <= #10:00:00 AM#, "按时", "未按时")
Case 2 To 4, 6, 7
If arr(i, 3) = "上午" Then
arr(i, 1) = IIf(CDate(arr(i, 1)) >= #9:00:00 AM# And _
CDate(arr(i, 1)) <= #10:00:00 AM#, "按时", "未按时")
Else
arr(i, 1) = IIf(CDate(arr(i, 1)) >= #2:30:00 PM# And _
CDate(arr(i, 1)) <= #3:30:00 PM#, "按时", "未按时")
End If
Case 5
arr(i, 1) = IIf(CDate(arr(i, 1)) >= #3:30:00 PM# And _
CDate(arr(i, 1)) <= #5:00:00 PM#, "按时", "未按时")
End Select
Next
[m2].Resize(UBound(arr, 1)) = arr
End Sub |