|
正常处理考勤需要每天的上班时间(最早时间)和下班时间(最晚时间),这种情况下,用数据透视表最方便,如下图所示——
如果需要像求助附件里的格式,把所有的打卡时间都列出来,需要借助于VBA,代码如下——
- Option Explicit
- Sub ShowData()
- Dim c As Range, i%, j%, arr(999, 9)
- With Sheet1
- For Each c In .Range("A2:A" & .[A2].End(xlDown).Row)
- If c.Value <> c.Offset(-1, 0).Value Then
- j = 0
- arr(i, j) = c.Value
- arr(i, j + 1) = c.Offset(0, 1).Value
- arr(i, j + 2) = Format(c.Offset(0, 2).Value, "hh:mm:ss")
- i = i + 1
- Else
- If c.Offset(0, 1).Value = c.Offset(-1, 1).Value Then
- j = j + 1
- arr(i - 1, j + 2) = Format(c.Offset(0, 2).Value, "hh:mm:ss")
- End If
- End If
- Next
- End With
- With Sheet2.[A2].Resize(1000, 10)
- .Cells.ClearContents
- .Cells = arr
- .Sort key1:=.Cells(1, 1), order1:=xlAscending, key2:=.Cells(1, 2), order2:=xlAscending, Header:=xlGuess
- End With
- End Sub
复制代码
具体效果看附件吧——
|
评分
-
1
查看全部评分
-
|