excel怎么用vba编写一个这样的程序,谢谢
展开全部
Sub 双字典统计()
Dim Rng As Range, Dic As Object, i&, Arr, Brr
Set Dic = CreateObject("Scripting.Dictionary")
Arr = [A2:C12]
For i = 1 To UBound(Arr)
If Not Dic.Exists(Arr(i, 1)) Then
Set Dic(Arr(i, 1)) = CreateObject("Scripting.Dictionary")
Dic(Arr(i, 1))(Arr(i, 2)) = Arr(i, 3)
Else
Dic(Arr(i, 1))(Arr(i, 2)) = Dic(Arr(i, 1))(Arr(i, 2)) + Arr(i, 3)
End If
Next i
Set Rng = [F1]
Brr = Dic.Keys
For i = 0 To UBound(Brr)
Rng.Offset(0, i * 2) = Brr(i)
Rng.Offset(1, i * 2).Resize(Dic(Brr(i)).Count, 2) = _
Application.WorksheetFunction.Transpose(Array(Dic(Brr(i)).Keys, Dic(Brr(i)).Items))
Set Dic(Brr(i)) = Nothing
Next i
Set Dic = Nothing
End Sub
追问
您的回答太棒了,谢谢,统计完的个数能加一个求个吗,谢谢谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询