|
- Sub 多表排重汇总()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary") '创建字典对象
- For Each sh In Worksheets
- If sh.Name <> "汇总" Then
- m = sh.Cells(Rows.Count, "a").End(xlUp).Row
- If m > 1 Then
- arr = sh.[a2].Resize(m - 1, 5)
- For i = 1 To UBound(arr)
- s = arr(i, 1) & "|" & arr(i, 2)
- If s <> Empty Then
- If Not d.Exists(s) Then
- d(s) = arr(i, 5)
- Else
- d(s) = d(s) + arr(i, 5)
- End If
- End If
- Next
- End If
- End If
- Next
- keys = d.keys
- items = d.items
- ReDim brr(1 To d.Count, 1 To 5)
- For i = 0 To d.Count - 1
- k = k + 1
- temp = Split(keys(i), "|")
- brr(k, 1) = temp(0)
- brr(k, 2) = temp(1)
- brr(k, 5) = items(i)
- Next
- With Sheets("汇总")
- .UsedRange.Offset(1) = ""
- .[a2].Resize(d.Count, 5) = brr
- .[a1].Resize(d.Count + 1, 5).Borders.LineStyle = 1
- End With
- Application.ScreenUpdating = True
- MsgBox "汇总完毕!"
- End Sub
复制代码 ykcbf1100老师代码基础上改为通常写法。
|
评分
-
1
查看全部评分
-
|