5种条件汇总方法,到底哪种才是最好的方法?
'作者:Excel办公实战-小易'日期:2020年9月2日'功能:条件汇总'-----------------------------------------Sub 条件汇总() Dim arr, d As Object, i As Long Set d = CreateObject("scripting.dictionary") arr = Sheets("Data").Range("A1").CurrentRegion '按名称汇总 For i = 2 To UBound(arr) d(arr(i, 2)) = d(arr(i, 2)) + arr(i, 5) Next '清空历史数据,写入汇总结果 With Sheets("VBA") .UsedRange.Clear .[A1:B1] = [{"名称","金额合计"}] .Range("A2").Resize(d.Count, 2) = _ Application.Transpose(Array(d.keys(), d.items())) End WithEnd Sub
赞 (0)