|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
vba初学者,试着用字典写一下,时间也很短,不到1秒
Sub 多条件汇总()
t = Timer
Dim dic1 As Object
Set dic1 = CreateObject("scripting.dictionary")
For Each sh In Worksheets
If sh.Name <> "汇总" Then
For i = 2 To sh.UsedRange.Rows.Count
If dic1.exists(sh.Cells(i, 1) & sh.Cells(i, 2)) Then
dic1(sh.Cells(i, 1) & sh.Cells(i, 2)) = dic1(sh.Cells(i, 1) & sh.Cells(i, 2)) + sh.Cells(i, 3)
Else
dic1(sh.Cells(i, 1) & sh.Cells(i, 2)) = sh.Cells(i, 3)
End If
Next i
End If
Next sh
For a = 2 To 31
For b = 3 To 29
Sheet1.Cells(b, a) = dic1(Sheet1.Cells(2, a) & Sheet1.Cells(b, 1))
Next b
Next a
dic1.RemoveAll
MsgBox Timer - t
End Sub |
|