|
楼主 |
发表于 2024-2-5 13:54
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
感谢各位老师帮忙
我用yynrzwh老师的代码,取消If d(s).Exists(ss) Then d(s).Remove ss这一行代码就可以
Sub 汇总()
Set d = New Dictionary
arr = Sheets("单价").Range("a1").CurrentRegion
For i = 2 To UBound(arr)
s = arr(i, 2)
If Not d.Exists(s) Then
Set d(s) = New Dictionary
End If
rq = Format(arr(i, 3), "yyyy年mm月dd日")
ss = rq & "|" & arr(i, 4)
d(s)(ss) = d(s)(ss) + arr(i, 5)
Next
With Sheets("资料")
lc = .Cells(1, Columns.Count).End(xlToLeft).Column
brr = .Range("a1").Resize(9999, lc)
For j = 1 To lc Step 3
lr = .Cells(Rows.Count, j).End(3).Row
s = brr(2, j)
If lr = 2 Then
Call sj(d, s, brr, j, lr)
Else
For i = 3 To lr
rq = Format(brr(i, j), "yyyy年mm月dd日")
brr(i, j) = rq
ss = rq & "|" & brr(i, j + 1)
Next
Call sj(d, s, brr, j, lr)
End If
Next
.Range("a1").Resize(9999, lc) = brr
End With
Set d = Nothing
End Sub
Sub sj(d, s, ByRef brr, j, lr)
For Each k In d(s).Keys
ar = Split(k, "|")
lr = lr + 1
brr(lr, j) = ar(0): brr(lr, j + 1) = ar(1)
brr(lr, j + 2) = d(brr(2, j))(k)
Next
End Sub
|
|