EXCEL通过VBA字典快速分类求和

EXCEL通过VBA字典快速分类求和

汇总截图

python 复制代码
Option Explicit

Option Explicit
Sub answer3()
Dim wb As Workbook
Dim sht As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Worksheets(2)
Dim ss1 As Integer
Dim ss2 As Integer
Dim i As Integer
Dim j As Integer
j = 1
    Dim aa()
    Dim b()
    Dim a()
    Dim d As Object, k As String
    Dim wReport As Worksheet, w As Worksheet
    Set w = wb.Worksheets(1)
    Set wReport = Worksheets(1)
    Set d = CreateObject("scripting.dictionary")
            aa = sht.UsedRange
            ss1 = sht.UsedRange.Rows.Count
            ss2 = UBound(aa)
            For i = 1 To UBound(aa)
                k = Trim(aa(i, 1))
                  If k <> "部门" Then
                    If d.exists(k) Then
                        d.Item(k) = CDbl(d.Item(k)) + CDbl(Trim(aa(i, 2)))
                    Else
                        d.Add k, CDbl(Trim(aa(i, 2)))
                    End If
                  End If
            Next i
       
    

    i = d.Count
    If i > 0 Then
    Dim Item As Variant
    For Each Item In d.keys()
        w.Cells(j, 1) = Item
        w.Cells(j, 2) = d(Item)
        j = j + 1
    Next
'        a = d.keys()
'        b = d.items()
'        w.Range(Cells(1, 1), Cells(i + 3, 1)) = Application.Transpose(a)
'        w.Range(Cells(1, 2), Cells(i + 3, 2)) = Application.Transpose(b)
    End If
    
    
    
End Sub
相关推荐
梦幻通灵10 小时前
Excel工作表的复制实战【实用指南】
excel
ManageEngineITSM13 小时前
功能越来越强,但 IT 使用体验却越来越差
大数据·excel·资产管理·itsm·工单系统
傻啦嘿哟13 小时前
如何使用 Python 操作 Excel 图片:插入、提取与压缩
开发语言·python·excel
石马马户13 小时前
Excel 根据A列标签拆分为多个列数据
excel
骆驼爱记录14 小时前
Word目录:标题加粗页码不加粗技巧
自动化·word·excel·wps·新人首发
城数派15 小时前
1985-2024年各省市县不同土地覆盖类型的土地面积(Excel)
数据库·arcgis·信息可视化·数据分析·excel
开开心心_Every15 小时前
轻松加密文件生成exe,无需原程序解密
运维·服务器·网络·电脑·excel·consul·memcache
fengyehongWorld2 天前
VBA 操作PowerQuery表格和带名字的表格
excel·vba
tangyal2 天前
Linux 核心操作合集(网络配置、XShell远程连接、vim文本编辑与操作、权限管理 实操手册)
excel
softbangong2 天前
815-批量Excel文件合并工具,批量excel文件、工作表合并软件
linux·windows·excel·文件合并·excel合并·数据整理