|
'可在[q2]、[q3]分别写入2015/3/3、2015/3/11 (就是例外处理,个数不限但为连续单元格)
'"多出很多",是你工作表的问题。已加条件避免出现这情况
Option Explicit
Sub test()
Dim mark, i, t, arr, a, b, dic
Set dic = CreateObject("scripting.dictionary")
If IsDate([q2]) Then '例外:[q2]开始,向下连续,行数不限
For i = 2 To Cells(Rows.Count, "q").End(xlUp).Row
If Not IsDate(Cells(i, "q")) Then Exit For
dic(CStr(Cells(i, "q"))) = vbNullString
Next
End If
arr = Range("k2:o2" & Cells(Rows.Count, "b").End(xlUp).Row)
mark = "一二三四五六日"
For i = 1 To UBound(arr, 1)
If dic.exists(CStr(arr(i, 1))) Then '例外处理
arr(i, 1) = IIf(CDate(arr(i, 2)) >= #6:00:00 AM# _
And CDate(arr(i, 2)) <= #6:00:00 PM#, "按时", "未按时")
Else
If arr(i, 2) = #12:00:00 AM# Then
If Len(arr(i, 2)) > 0 Then arr(i, 1) = "无考勤记录"
Else
t = InStr(mark, Right(arr(i, 4), 1))
Select Case t
Case 1: a = #9:00:00 AM#: b = #10:00:00 AM#
Case 2 To 4, 6, 7
If arr(i, 5) = "上午" Then
a = #9:00:00 AM#: b = #10:00:00 AM#
Else
a = #2:30:00 PM#: b = #3:30:00 PM#
End If
Case 5: a = #3:30:00 PM#: b = #5:00:00 PM#
End Select
arr(i, 1) = IIf(CDate(arr(i, 2)) >= a And _
CDate(arr(i, 2)) <= b, "按时", "未按时")
End If
End If
Next
[m2].Resize(UBound(arr, 1)) = arr
End Sub |
评分
-
1
查看全部评分
-
|