|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 汇总()
Dim ar As Variant, cr As Variant
Dim i As Long, r As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("情况")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "情况工作表为空!": End
ar = .Range("a1:e" & r)
End With
ReDim br(1 To UBound(ar, 2), 1 To 2)
br(1, 1) = "产品名称"
br(1, 2) = "金额合计"
For j = 2 To UBound(ar, 2)
br(j, 1) = ar(1, j)
For i = 2 To UBound(ar)
If ar(i, j) <> "" Then
br(j, 2) = br(j, 2) + ar(i, 1)
End If
Next i
Next j
With Sheets("结果")
.[a1].CurrentRegion = Empty
.[a1].Resize(UBound(br), UBound(br, 2)) = br
End With
MsgBox "ok!"
End Sub |
|