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
相关推荐
Abigail_chow4 小时前
EXCEL如何快速批量给两字姓名中间加空格
windows·microsoft·excel·学习方法·政务
xiaohezi15 小时前
Rag chunk 之:Excel 文档解析
excel
weixin_4723394619 小时前
python批量解析提取word内容到excel
python·word·excel
1 天前
Unity与Excel表格交互热更方案
unity·游戏引擎·excel
金融小白数据分析之路1 天前
Excel高级函数使用FILTER、UNIQUE、INDEX
excel
未来之窗软件服务1 天前
Excel表格批量下载 CyberWin Excel Doenlaoder 智能编程-——玄武芯辰
excel·批量下载·仙盟创梦ide·东方仙盟
阿斯加德的IT2 天前
Power Automate: 从Excel 选择列,每200条生成一个CSV文件并保存在sharepoint文档库
低代码·excel
步达硬件2 天前
【转bin】EXCEL数据转bin
excel
wtsolutions2 天前
JSON to Excel 3.0.0 版本发布 - 从Excel插件到Web应用的转变
json·excel·json-to-excel·wtsolutions
cnfelix2 天前
vim&adb&git命令
elasticsearch·vim·excel