|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 lele400024 于 2016-7-10 14:11 编辑
我可能是没有表述清楚,我有一个实际案例,数据结构是基本一样的,我上传附件,麻烦你看看,谢谢
提问20060710.rar
(33.44 KB, 下载次数: 28)
原始数据
实现效果
部分代码如下,
- Sub 汇总()
- Dim i, j, arr, dic As Object, u, temp
- j = Sheet10.[a65536].End(3).row
- ar = Sheet10.Range("A2:g" & j)
- Set dic = CreateObject("Scripting.Dictionary")
- ReDim temp(1 To 10000, 1 To 12)
- For i = 1 To UBound(ar)
- If Not dic.exists(ar(i, 6) & ar(i, 1)) Then
- k = k + 1: dic(ar(i, 6) & ar(i, 1)) = k
- temp(k, 1) = ar(i, 1)
- temp(k, 9) = ar(i, 3)
- temp(k, 10) = ar(i, 4)
- temp(k, 12) = ar(i, 6)
- temp(k, 11) = temp(k, 9) + Int(temp(k, 10) / 60) & "小时" & temp(k, 10) Mod 60 & "分钟"
- Else
- u = dic(ar(i, 6) & ar(i, 1))
- temp(u, 9) = temp(u, 9) + ar(i, 3)
- temp(u, 10) = temp(u, 10) + ar(i, 4)
- temp(u, 11) = (temp(u, 9) + Int(temp(u, 10) / 60)) & "小时" & temp(u, 10) Mod 60 & "分钟"
- End If
- Next
- Sheet2.[a1].Resize(k, 12) = temp
- Set dic = Nothing
-
- End Sub
复制代码
|
|