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
相关推荐
懵逼的小黑子11 小时前
excel里面店铺这一列的数据结构是2C【uniteasone17】这种,我想只保留前面的2C部分,后面的【uniteasone17】不要
excel
偷心伊普西隆15 小时前
Python EXCEL 理论探究:格式转换时处理缺失值方法
python·excel
CodeCraft Studio2 天前
Excel处理控件Aspose.Cells教程:使用 Python 将 Pandas DataFrame 转换为 Excel
python·json·excel·pandas·csv·aspose·dataframe
星空的资源小屋2 天前
PPTist,一个完全免费的 AI 生成 PPT 在线网站
人工智能·python·电脑·excel
开开心心_Every2 天前
免费语音合成工具:66种音色随心选
人工智能·面试·java-ee·计算机外设·电脑·maven·excel
偷心伊普西隆2 天前
EXCEL VBA 清空Excel工作表(Sheet)的方法
microsoft·excel
Coding_Doggy3 天前
苍穹外卖Day12 | Apache POI、导出Excel报表、HttpServletResponse、工作台
excel
l1t3 天前
张泽鹏先生手搓的纯ANSI处理UTF-8与美团龙猫调用expat库读取Excel xml对比测试
xml·人工智能·excel·utf8·expat
Source.Liu4 天前
【Python自动化】 21 Pandas Excel 操作完整指南
python·excel·pandas
会飞的小菠菜4 天前
如何根据Excel数据表生成多个合同、工作证、录取通知书等word文件?
word·excel·模板·数据表·生成文件