Sub text()
Dim arr, brr
Dim x
Dim dic
Set dic = CreateObject("scripting.dictionary")
arr = Sheets("数据源").[a1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 5)
For x = 2 To UBound(arr)
If Not dic.exists(arr(x, 4)) Then
dic(arr(x, 4)) = dic.Count + 1
brr(dic(arr(x, 4)), 1) = arr(x, 4)
brr(dic(arr(x, 4)), 2) = Val(arr(x, 5))
brr(dic(arr(x, 4)), 5) = Val(arr(x, 18))
Else
brr(dic(arr(x, 4)), 2) = brr(dic(arr(x, 4)), 2) + Val(arr(x, 5))
brr(dic(arr(x, 4)), 5) = brr(dic(arr(x, 4)), 5) + Val(arr(x, 18))
End If
Next
Sheets("汇总结果").UsedRange.ClearContents
Sheets("汇总结果").Range("a1:e1") = Array("供应商名称", "数量", , , "金额")
Sheets("汇总结果").[a2].Resize(dic.Count, 5) = brr
End Sub
|