ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 85|回复: 4

[求助] 打卡记录按照规定上下班时间设置迟到、早退对应颜色。具体见附件

[复制链接]

TA的精华主题

TA的得分主题

发表于 2024-4-11 09:16 | 显示全部楼层 |阅读模式
本帖最后由 小洛1986 于 2024-4-11 09:16 编辑

打卡记录按照规定上下班时间设置迟到、早退对应颜色。具体见附件

打卡记录.zip

12.42 KB, 下载次数: 6

TA的精华主题

TA的得分主题

发表于 2024-4-11 09:50 | 显示全部楼层
1,目前这样的考勤记录方式,想用条件格式来实现你需要的效果基本上是不可能的
2、及时用条件格式设置了,你不还得来根据填充颜色来统计吗?
3、为何不一步到位,直接统计每个人迟到,早退,的次数呢?
4、单元格中石油一次打卡记录的如何统计??

TA的精华主题

TA的得分主题

发表于 2024-4-11 10:25 | 显示全部楼层
Sub biaojiyanse()
Dim rn1 As Range, rn2 As Range, rn3 As Range
With ActiveSheet
    r = .Cells(Rows.Count, 2).End(xlUp).Row
    y = .Cells(2, Columns.Count).End(xlToLeft).Column
    If r < 4 Then MsgBox "考勤表为空,请先导入数据!": End
    ar = .Range(.Cells(1, 1), .Cells(r, y))
    sb = "8:00:00" ' .[d1]
    xb = "17:00:00" ' .[g1]
    For i = 4 To UBound(ar)
        For j = 3 To UBound(ar, 2)
            x = 0: w = 0
            If ar(i, j) <> Empty Then
                If ar(i, j) <> "-" Then
                    If InStr(ar(i, j), Chr(10)) = 0 Then
                        sj = ar(i, j)
                        If TimeValue(sj) > TimeValue(sb) And TimeValue(sj) < TimeValue("12:00:00") Then
                            If rn1 Is Nothing Then
                                Set rn1 = .Cells(i, j) ''迟到
                            Else
                                Set rn1 = Union(rn1, .Cells(i, j))
                            End If
                        ElseIf TimeValue(sj) > TimeValue("12:00:00") And TimeValue(sj) < TimeValue(xb) Then
                            If rn2 Is Nothing Then
                                Set rn2 = .Cells(i, j) ''早退
                            Else
                                Set rn2 = Union(rn2, .Cells(i, j))
                            End If
                        End If
                    ElseIf InStr(ar(i, j), Chr(10)) > 0 Then
                        rr = Split(ar(i, j), Chr(10))
                        sj_1 = rr(0)
                        If TimeValue(sj_1) > TimeValue(sb) And TimeValue(sj_1) < TimeValue("12:00:00") Then
                            x = x + 1
                            If rn1 Is Nothing Then
                                Set rn1 = .Cells(i, j)
                            Else
                                Set rn1 = Union(rn1, .Cells(i, j))
                            End If
                        End If
                        sj_2 = rr(UBound(rr))
                        If TimeValue(sj_2) > TimeValue("12:00:00") And TimeValue(sj_2) < TimeValue(xb) Then
                            w = w + 1
                            If rn2 Is Nothing Then
                                Set rn2 = .Cells(i, j)
                            Else
                                Set rn2 = Union(rn2, .Cells(i, j))
                            End If
                        End If
                        If x <> 0 And w <> 0 Then
                            If rn3 Is Nothing Then
                                Set rn3 = .Cells(i, j)
                            Else
                                Set rn3 = Union(rn3, .Cells(i, j))
                            End If
                        End If
                    End If
                End If
            End If
        Next j
    Next i
    .Range(.Cells(4, 1), .Cells(r, y)).Interior.ColorIndex = 0
    If Not rn1 Is Nothing Then rn1.Interior.ColorIndex = 23
    If Not rn2 Is Nothing Then rn2.Interior.ColorIndex = 22
    If Not rn3 Is Nothing Then rn3.Interior.ColorIndex = 6
End With
MsgBox "ok!"
End Sub

TA的精华主题

TA的得分主题

发表于 2024-4-11 10:26 | 显示全部楼层
打卡记录.rar (21.31 KB, 下载次数: 4)

TA的精华主题

TA的得分主题

发表于 2024-4-11 10:27 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-2 09:18 , Processed in 0.034250 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表