首页 /编程语言和算法/VB6/VBA/ASP
 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


 
全部回复(0)
首页 | 电脑版 |