|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 统计()
Dim arr()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheet1
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:c" & r)
y = .Cells(2, Columns.Count).End(xlToLeft).Column
rs = .Cells(Rows.Count, 8).End(xlUp).Row + 1
br = .Range(.Cells(1, 7), .Cells(rs, y))
For j = 2 To UBound(br, 2)
If Trim(br(2, j)) <> "" Then
d(Trim(br(2, j))) = j
End If
Next j
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
lh = d(Trim(ar(i, 1)))
If lh <> "" Then
br(rs, lh) = br(rs, lh) + ar(i, 3)
End If
End If
If Trim(ar(i, 2)) <> "" Then
lh = d(Trim(ar(i, 2)))
If lh <> "" Then
br(rs, lh) = br(rs, lh) + ar(i, 3)
End If
End If
Next i
For j = 2 To UBound(br, 2)
If rs = 2 Then
.Cells(rs, j + 6) = br(rs, j)
ElseIf rs > 2 Then
.Cells(rs, j + 6) = .Cells(rs - 1, j + 6) + br(rs, j)
End If
Next j
End With
MsgBox "ok!"
End Sub
|
|