|
- Option Explicit
- Sub 生成报表()
- Dim arr, i&, n%, s$, x%, y%
- Dim d As Object, k, p, t As Date
- Rem 读取计算当月的最末日期
- With Sheet2
- t = DateSerial(.Range("H1").Value, .Range("I1").Value + 1, 0)
- End With
- Rem 读取打卡记录
- Set d = CreateObject("Scripting.Dictionary")
- arr = Sheet1.Range("A1").CurrentRegion.Value
- For i = 2 To UBound(arr)
- s = arr(i, 1) & "|" & arr(i, 2)
- If Not d.Exists(s) Then
- d(s) = i
- Else
- d(s) = d(s) & "|" & i
- End If
- Next
- Rem 整理打卡记录
- ReDim temp(1 To Day(t) * 2 + 2, 1 To d.Count * 2)
- For Each k In d.keys
- temp(1, x * 2 + 1) = Split(k, "|")(0) '工号
- temp(2, x * 2 + 1) = Split(k, "|")(1) '姓名
- For Each p In Split(d.Item(k), "|")
- y = Day(arr(Val(p), 3)) * 2 + 1
- If temp(y, x * 2 + 1) = "" Then
- temp(y, x * 2 + 1) = Format(arr(Val(p), 3), "h:mm:ss")
- Else
- temp(y + 1, x * 2 + 1) = Format(arr(Val(p), 3), "h:mm:ss")
- End If
- Next
- x = x + 1 '指针右移
- Next
- Rem 向汇总表写入记录
- Application.ScreenUpdating = False
- For i = 1 To d.Count
- Sheet2.Cells(2, i * 2).Resize(1000).ClearContents
- Sheet2.Cells(2, i * 2).Resize(UBound(temp)) = Application.Index(temp, , i * 2 - 1)
- Next i
- Application.ScreenUpdating = True
- Set d = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|