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 小时前
EasyExcel使用
java·开发语言·excel
图片转成excel表格7 小时前
Excel中怎么提取超出部分数值,比如5w是目标,超出100%和120%的值怎么用公式提取?
excel
周末zm13 小时前
golang将word、excel转换为pdf
pdf·word·excel
孟秋与你14 小时前
【excel】easy excel如何导出动态列
java·excel
Say Bay To The Bugs16 小时前
EasyExcel 使用多线程按顺序导出数据
开发语言·excel
机器懒得学习16 小时前
Python & PyQt5 实现 .his 文件批量转 Excel 工具
开发语言·python·excel
可靠百灵鸟16 小时前
Python 操作 Excel 表格从简单到高级用法
开发语言·python·excel
理想不理想v21 小时前
[经典] 前端js将文件流导出为csv/excel文件
前端·javascript·excel
m0_5898288721 小时前
Excel根据条件动态索引单元格范围
excel
匆匆整棹还21 小时前
已有账号,重装系统激活office后发现没有ppt,word,excel等
word·powerpoint·excel