|
各位老师:搜索前辈分类汇总代码如下:
有两问点请教,详见附件,谢谢!
1、arr1(i, 1) 的汇总数 如何添加
2、Range("f17").Resize(k, 4) = arr 如何修改指定列(不一定是连续列)输出。
Dim arr(1 To 10000, 1 To 4), arr1, dic As Object, i As Long, k As Long, hang As Long, Maxrow As Long, t As Single
Maxrow = Cells(Rows.Count, 1).End(xlUp).Row
Set dic = CreateObject("scripting.dictionary")
arr1 = Range("A2:D" & Maxrow)
For i = 1 To UBound(arr1, 1)
Mystring = arr1(i, 1) & arr1(i, 2)
If dic.Exists(Mystring) Then
hang = dic(Mystring)
arr(hang, 3) = arr(hang, 3) + arr1(i, 3)
arr(hang, 4) = arr(hang, 4) + arr1(i, 4)
Else
k = k + 1
dic(Mystring) = k
arr(k, 1) = arr1(i, 1)
arr(k, 2) = arr1(i, 2)
arr(k, 3) = arr1(i, 3)
arr(k, 4) = arr1(i, 4)
End If
Next i
[F16:M16] = Array("产品名称", "型号", "数量", "金额") '
Range("f17").Resize(k, 4) = arr
|
|