|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 求和()
Dim ar As Variant, br As Variant
Dim i As Long, r As Long, rs As Long
Dim d As Object, dc 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:b" & r)
End With
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
d(ar(i, 1)) = d(ar(i, 1)) + ar(i, 2)
End If
Next i
With Sheets("统计")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs < 2 Then MsgBox "统计为空!": End
.Range("g2:g" & rs) = Empty
br = .Range("a1:g" & rs)
For i = 2 To UBound(br)
If br(i, 3) <> "" Then
br(i, 7) = d(br(i, 3))
End If
Next i
.[g1].Resize(UBound(br), 1) = Application.Index(br, 0, 7)
End With
MsgBox "ok!"
End Sub
|
|