VBA透视表式汇总

Sub 透视表式汇总()
        Dim d As Object, arr, x&, y%, s, t, a, b, m%, n%, r%
        Dim sh  As Worksheet
        Application.ScreenUpdating = False
        Set d = CreateObject("scripting.dictionary")
        Application.DisplayAlerts = False
        For Each sh In Worksheets
             If Not sh.Name Like "合并结果" Then
                     sh.Delete
             End If
        Next sh
        Application.DisplayAlerts = True
        Sheets.Add(after:=Sheets(Sheets.Count)).Name = "透视表式汇总"
        Sheets("合并结果").Activate
        arr = Range("a1").CurrentRegion
        For x = 2 To UBound(arr)
                If Not d.exists(arr(x, 4)) Then
                        Set d(arr(x, 4)) = CreateObject("scripting.dictionary")
                End If
                d(arr(x, 4))(arr(x, 12)) = d(arr(x, 4))(arr(x, 12)) + arr(x, 9)
        Next x
                s = d.keys: t = d.items
        Sheets("透视表式汇总").Activate
        For m = 0 To d.Count - 1
                a = d(s(m)).keys: b = d(s(m)).items
                n = n + r
                With Sheets("透视表式汇总")
                        .Cells(1, 1).Resize(1, 3) = Array("门店", "型号", "数量")
                        .Cells(2 + n, 1).Resize(d(s(m)).Count, 1) = s(m)
                        .Cells(2 + n, 2).Resize(d(s(m)).Count, 1) = Application.Transpose(a)
                        .Cells(2 + n, 3).Resize(d(s(m)).Count, 1) = Application.Transpose(b)
                        n = 0
                End With
                r = Cells(Rows.Count, 1).End(xlUp).Row - 1
        Next m
        Range("a:c").EntireColumn.AutoFit
        Application.ScreenUpdating = True
End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

豪情云天

您的鼓励就是创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值