|
本帖最后由 335356119 于 2018-9-16 15:31 编辑
我想把图片中的考勤明细和产量明细,经过处理后,自动填充到产量考勤汇总的表格里。之前坛友帮助提供的代码已经能解决问题了。但我想把代码综合起来,节约计算时间。
考勤的汇总,根据汇总表格里,已经填写的组别次序,自动填充姓名/人数/小组工时(小组工时用同组人员的下班时间总和-上班时间总和-休息时间总和)。
产量的汇总,同组生产的不同产品名称(次数)的,其产品名,加工产量,人均产量,需要在同单元格下一一对应的以“/”分割开。(第一张图没有填写产品,产量,平均产量的样式,第四张(简配版,效果应该是填写在第一张图)是。
谢谢@不知道为什么以及各位提供的热心帮助,由于我vba不精通,又使用了函数进行辅助。两端代码完美使用,本来我想这想尝试把这两段代码综合到一起使用。发现涉及到字典keys对应的问题,小弟无力解决,求各位帮助。两端代码应以附件中“小组”编号为 Keys ,进行查询填充文字。
- Sub 更新考勤()
- Dim Dic, Arr, Brr()
- Set Dic = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- With Sheets("考勤明细")
- Arr = .[a1].CurrentRegion
- For i = 2 To UBound(Arr)
- If Not Dic.exists(DateValue(Arr(i, 1))) Then
- Set Dic(DateValue(Arr(i, 1))) = CreateObject("scripting.dictionary")
- End If
- If Not Dic(Arr(i, 1)).exists(Arr(i, 3)) Then
- Set Dic(DateValue(Arr(i, 1)))(Arr(i, 3)) = CreateObject("scripting.dictionary")
- End If
- Dic(DateValue(Arr(i, 1)))(Arr(i, 3))(Arr(i, 2)) = Dic(DateValue(Arr(i, 1)))(Arr(i, 3))(Arr(i, 2)) + 1
- Next i
- End With
- ReDim Brr(1 To UBound(Arr), 1 To 9)
- With Sheets("产量考勤汇总")
- .[h3].Resize(1000, 9).ClearContents
- If Dic.exists(DateValue(.Range("a1"))) Then
- For Each k In Dic(DateValue(.Range("a1"))).keys
- x = x + 1
- Brr(x, 8) = k
- For Each kl In Dic(DateValue(.Range("a1")))(k).keys
- Brr(x, 9) = Join(Dic(DateValue(.Range("a1")))(k).keys, " ")
- Brr(x, 6) = Dic(DateValue(.Range("a1")))(k).Count
- Next
- Next
- End If
- If x Then
- .[h3].Resize(x, 9) = Brr
- End If
- End With
- Set Dic = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码- Sub 更新产量()
- Dim Dic, Arr, Brr()
- Set Dic = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- Arr = Sheets("产量明细").[a1].CurrentRegion
- ReDim Brr(1 To UBound(Arr), 1 To 10)
- For i = 2 To UBound(Arr)
- rq = DateValue(Arr(i, 1))
- If Not Dic.exists(rq) Then
- Set Dic(rq) = CreateObject("scripting.dictionary")
- End If
-
- If Not Dic(rq).exists(Arr(i, 3)) Then
- Set Dic(rq)(Arr(i, 3)) = CreateObject("scripting.dictionary")
- End If
- Dic(rq)(Arr(i, 3))(Arr(i, 2)) = Dic(rq)(Arr(i, 3))(Arr(i, 2)) + Arr(i, 5)
- Next i
- With Sheets("产量考勤汇总")
- rq = DateValue(.Cells(1, 1))
- If Dic.exists(rq) Then
- For Each k In Dic(rq).keys
- x = x + 1
- Brr(x, 6) = k
- For i = 2 To UBound(Arr)
- If DateValue(Arr(i, 1)) = rq And Arr(i, 3) = k Then
- s = s + 1
- End If
- Next i
- Brr(x, 4) = s: s = 0
- For Each k1 In Dic(rq)(k).keys
- Brr(x, 1) = Join(Dic(rq)(k).keys, "/")
- Brr(x, 3) = Join(Dic(rq)(k).items, "/")
- Next
- Next
- End If
- For i = 1 To x
- If InStr(Brr(i, 3), "/") Then
- For n = 0 To UBound(Split(Brr(i, 3), "/"))
- pj = Val(Split(Brr(i, 3), "/")(n)) \ Brr(i, 4)
- mm = mm & "/" & pj
- Next n
- Brr(i, 5) = Right(mm, Len(mm) - 1): mm = ""
- Else
- Brr(i, 5) = Brr(i, 3) \ Brr(i, 4)
- End If
- Next i
- .[a3:f999].ClearContents
- .[a3].Resize(x, 6) = Brr
- .Activate
- End With
- Set Dic = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|