excel中实现数据自动汇总到汇总表的常用办法是vba汇总,高效快速。
操作方法如下:
打开excel,按住alt+F11打开VBA编辑器:
新建一个模块,贴入以下代码:
Sub 汇总()
Dim d As Object
Dim Arr As Variant
Arr =Worksheets("数据源").Range("A2:B" & Worksheets("数据源").Range("B"& Rows.Count).End(xlUp).Row)
Dim i As Long
Set d =CreateObject("Scripting.dictionary")
For i = 1 ToUBound(Arr)
d(Arr(i, 1)) =d(Arr(i, 1)) + Arr(i, 2)
Next i
Range("A1:B1") = Array("产品编码", "数量")
Range("A2").Resize(d.Count) =Application.WorksheetFunction.Transpose(d.keys)
Range("B2").Resize(d.Count) =Application.WorksheetFunction.Transpose(d.items)
With Range("a1").CurrentRegion
.Borders.LineStyle = xlContinuous
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Sub
3.指定执行的宏: