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
相关推荐
醉卧考场君莫笑6 小时前
excel数据统计与数据可视化
信息可视化·excel
weixin_440401697 小时前
WPS Excel 宏使用
excel··wps
GalenZhang8887 小时前
Excel/WPS 表格数据合并操作指南
excel·wps
海拥✘8 小时前
Excel制作跳动爱心动画:一步步创建动态数学心形图
excel
教练、我想打篮球9 小时前
127 apache poi3.11 写 word 中内嵌 表格换行的输出
word·excel·docx·换行
醉卧考场君莫笑1 天前
EXCEL数据分析基础(没有数据统计和数据可视化)
信息可视化·数据分析·excel
yesyesyoucan1 天前
智能文件格式转换平台:文本/Excel与CSV的无缝互转解决方案
excel
hqyjzsb1 天前
2026年AI证书选择攻略:当“平台绑定”与“能力通用”冲突,如何破局?
大数据·c语言·人工智能·信息可视化·职场和发展·excel·学习方法
牛奔1 天前
Linux 的日志分析命令
linux·运维·服务器·python·excel
不吃葱的胖虎1 天前
根据Excel模板,指定单元格坐标填充数据
java·excel