|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 统计()
Dim ar As Variant
Dim i As Long, r As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheet1
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:b" & r)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
ys = .Cells(i, 2).Interior.ColorIndex
d(ys) = d(ys) + ar(i, 1)
End If
Next i
rs = .Cells(Rows.Count, 4).End(xlUp).Row
.Range("d2:e" & rs + 1).Clear
.[d2].Resize(d.Count, 2) = Application.Transpose(Array(d.keys, d.items))
For i = 2 To d.Count + 1
.Cells(i, 4).Interior.ColorIndex = .Cells(i, 4)
Next i
End With
MsgBox "ok!"
End Sub
|
|