|
楼主 |
发表于 2018-9-9 06:12
|
显示全部楼层
本帖最后由 风雨相随3 于 2018-9-13 18:16 编辑
计算时间2003.rar
(15.32 KB, 下载次数: 2)
Sub 出勤()Dim Arr, Brr, i%, WT%, wD$, x%, y&, wDa&, wDe&, wdi&, wDee&
Set Dic = CreateObject("Scripting.Dictionary")
Application.ScreenUpdating = False
Arr = Sheets("出勤时间").[a1].CurrentRegion
ReDim Brr(1 To UBound(Arr), 1 To 100)
x = 1: y = 2
For i = 2 To UBound(Arr)
WT = Arr(i, 6) + Arr(i, 7) + Arr(i, 8) + Arr(i, 9)
wDa = Day(Arr(i, 1))
wDe = WorksheetFunction.Weekday(Arr(i, 1), 2)
wDee = WorksheetFunction.Weekday(Arr(i, 1) - wDa + 1, 2)
wdi = Int(((wDa - 1) / 7) + 1 + (wDee > wDe) * 1)
wD = "第" & wdi & "周"
'wD = "第" & WorksheetFunction.WeekNum(Arr(i, 1)) & "周"
If Not Dic.exists(wD) Then
y = y + 1
Dic(wD) = y
Brr(1, y) = wD
End If
If Not Dic.exists(Arr(i, 2)) Then
x = x + 1
Dic(Arr(i, 2)) = x
Brr(x, 1) = Arr(i, 2): Brr(x, 2) = Arr(i, 3)
Brr(x, Dic(wD)) = WT
Else
Brr(Dic(Arr(i, 2)), Dic(wD)) = Brr(Dic(Arr(i, 2)), Dic(wD)) + WT
End If
Next i
Brr(1, 2) = "姓名"
Brr(1, 1) = "工号"
With Sheets("汇算")
.Cells.ClearContents
.[a1].Resize(x, y) = Brr
End With
Set Dic = Nothing
Application.ScreenUpdating = True
End Sub
为适应excel2003我改了黄色部分代码,测试后生成“第1周”、“第0周”、“第2周”、“第3周”、“第4周”、“第5周”,而不是1-6周。请问我错在什么地方?
如果要写入Brr (1,3)=“部门”该改那些地方? |
|