|
各位老师:
烦请帮忙查看一下代码哪里出错了,测试了许久,水平有限没有找到原因。
烦请老师帮忙看看。
把符合【总表】A列&B列的【明细】表数据从该表第8列-130列的折算数量汇总(PC数量不汇总),汇总至总表的第6列-66列数据
然后在67列对6-66列的数据进行合计
非常感谢
Sub 测试1()
Dim row1, row2, arr1, arr2, i As Long, j As Long, k As Long
Set dic = CreateObject("scripting.dictionary")
row1 = Sheets("明细").Cells(Rows.Count, 1).End(xlUp).Row
row2 = Sheets("总表").Cells(Rows.Count, 1).End(xlUp).Row
arr = Sheets("明细").Range("a6:fo" & row1 + 2)
brr = Sheets("总表").Range("a5:cy" & row2 + 4)
For i = 1 To UBound(arr)
For j = 8 To 130 Step 2 '明细表从第8列开始的折算数量
If InStr(arr(i, 2), "停用") < 0 Then
s = Trim(arr(i, 1)) & Trim(arr(i, 2)) '匹配的2个关键值
dic(s) = dic(s) + arr(i, j)
End If
Next
Next
For k = 1 To UBound(brr)
If dic.exists(Trim(brr(k, 1)) & Trim(brr(k, 2))) Then
x = Trim(brr(k, 1)) & Trim(brr(k, 2))
For j = 6 To 66 Step 1 '将明细的数量汇总到汇总表的第6列-66列,然后在67列对6-66列的数据进行汇总
brr(k, f) = dic(x)
Next
End If
Next
Sheets("总表").Range("f4:bn65536").ClearContents
Sheets("总表").Range("f4:bn" & row2) = arr
End Sub
|
|