|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
这种格式的数据,用公式已经很为难了,所以帮你写了个自定义函数,如下图所示——
自定义函数的代码如下——
- Function kqtj(rng As Range, str As String, mth As String)
- Dim c As Range, sbsj As Date, xbsj As Date, arr
- Dim i% '休息天数
- Dim j% '异常打卡次数
- Dim k% '请假天数
- Dim l% '迟到次数
- Dim m% '早退次数
- sbsj = TimeValue("8:00") '上班时间
- xbsj = TimeValue("17:00") '下班时间
- If Not rng Is Nothing Then
- For Each c In rng
- If Len(c.Value) > 0 Then
- arr = Split(c.Value, " ")
- If CDate(arr(0)) > sbsj And CDate(arr(0)) <= DateAdd("n", 15, sbsj) Then
- l = l + 1
- ElseIf CDate(arr(0)) > DateAdd("n", 15, sbsj) Then
- j = j + 1
- End If
- If CDate(arr(UBound(arr) - 1)) < xbsj And CDate(arr(UBound(arr) - 1)) >= DateAdd("n", -15, xbsj) Then
- m = m + 1
- ElseIf CDate(arr(UBound(arr) - 1)) < DateAdd("n", -15, xbsj) Then
- j = j + 1
- End If
- Else
- i = i + 1
- If Weekday(CDate(mth & "-" & c.Offset(-1, 0)), vbMonday) < 6 Then k = k + 1
- End If
- Next
- End If
- Select Case str
- Case "休息天数"
- kqtj = i
- Case "异常打卡次数"
- kqtj = j
- Case "请假天数"
- kqtj = k
- Case "迟到次数"
- kqtj = l
- Case "早退次数"
- kqtj = m
- Case Else
- kqtj = "#VAL"
- End Select
- End Function
复制代码 附件如下——
|
|