|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
下面是合计数量的代码,现在求平均数量的代码,请老师帮助。
Private Sub 合计数量_Click()
Dim r%, i%
Dim Arr, brr
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Worksheets("sheet1")
r = .Cells(.Rows.Count, 2).End(xlUp).Row
.Range("E" & r + 1 & ":F65536").ClearContents
Arr = .Range("B5:F" & r)
For i = 1 To UBound(Arr)
If Not d.Exists(Arr(i, 1)) Then
ReDim brr(1 To 2)
brr(1) = Arr(i, 1)
Else
brr = d(Arr(i, 1))
End If
brr(2) = brr(2) + Arr(i, 2)
d(Arr(i, 1)) = brr
Next i
Range("E" & 5).Resize(d.Count, UBound(brr)) = Application.Transpose(Application.Transpose(d.Items))
End With
End Sub
附件:
附件.rar
(10.75 KB, 下载次数: 2)
|
|