|
请版主指点.
销量汇总.rar
(27.29 KB, 下载次数: 166)
- Sub bbb()
- Dim i&, ii&, y&, tmp$, arr1(), arr2(), arr3()
- Dim dic1 As Object, Sh As Object
-
- Set dic1 = CreateObject("scripting.dictionary")
-
- arr1 = garr("总表")
-
- '添加汇总字典key
- For i = 3 To UBound(arr1)
- For ii = 3 To UBound(arr1, 2)
- tmp = arr1(i, 1) & arr1(i, 2) & Mid(arr1(1, ii), 2) & arr1(2, ii)
- dic1(tmp) = 0
- Next
- Next
-
- '循环分表并汇总于字典item
- For Each Sh In ThisWorkbook.Sheets
- If Sh.Name <> "总表" Then
- arr2 = garr(Sh.Name)
- For i = 3 To UBound(arr2)
- For ii = 3 To UBound(arr2, 2)
- tmp = arr2(i, 1) & arr2(i, 2) & Mid(arr2(1, ii), 2) & arr2(2, ii)
- If dic1.exists(tmp) Then dic1(tmp) = dic1(tmp) + arr2(i, ii)
- Next
- Next
- End If
- Next
-
- '对号入坐汇总值
- arr3 = dic1.items
- For i = 3 To UBound(arr1)
- For ii = 3 To UBound(arr1, 2)
- arr1(i, ii) = arr3(y)
- y = y + 1
- Next
- Next
-
- Sheets("总表").[b2].Resize(UBound(arr1), UBound(arr1, 2)).Value = arr1
- End Sub
- Function garr(shn As String) '重新填写表头,处理合并单元格数据
- Dim i&, arrTmp()
-
- With Sheets(shn)
- arrTmp = .[b2].Resize(.[b65536].End(3).Row - 2, .[iv2].End(1).Column - 2).Value '取数
- End With
- For i = 4 To UBound(arrTmp)
- If Len(arrTmp(i, 1)) = 0 Then arrTmp(i, 1) = arrTmp(i - 1, 1) '填写表头
- Next
- For i = 4 To UBound(arrTmp, 2)
- If Len(arrTmp(1, i)) = 0 Then arrTmp(1, i) = arrTmp(1, i - 1)
- Next
- garr = arrTmp
- End Function
复制代码 |
|