查看: 24  |  回复: 0
  VBA代码 字典模板
楼主
发表于 2025年3月18日 10:12
Sub 字典求和套路()
   Dim i, j, arr, brr, key
   Dim sht As Worksheet
   Set sht = Sheet1
   Application.Calculation = xlManual
   Dim dic
   Set dic = CreateObject("scripting.dictionary")
   
   For i = 3 To sht.Cells(Rows.Count, "A").End(xlUp).Row
       key = sht.Cells(i, "A")
       dic(key) = dic(key) + sht.Cells(i, "C") '求和
   Next
   
   Sheet3.Range("A2").Resize(10000, 2).ClearContents '清空结果区
   Sheet3.Range("A2").Resize(dic.Count, 2) = Application.Transpose(Array(dic.keys, dic.items)) '结果区
   Application.Calculation = xlAutomatic
End Sub


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com