|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
参与一下。。。- Sub 多工作表汇总() '//不限工作表,2024.1.20
- Dim tm: tm = Timer
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set sh = Sheets("汇总")
- sh.Range("a2:f10000").ClearContents
- For Each sht In Worksheets
- If sht.Name <> sh.Name Then
- With sht
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .Range("a1:m" & r)
- fn = .Name
- End With
- For i = 2 To UBound(arr)
- For j = 2 To UBound(arr, 2)
- s = arr(i, 1) & "|" & arr(1, j) & "|" & fn
- d(s) = d(s) + arr(i, j)
- Next
- Next
- End If
- Next
- With sh
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .Range("a1:f" & r)
- For i = 2 To UBound(arr)
- For j = 3 To UBound(arr, 2)
- s = arr(i, 1) & "|" & arr(i, 2) & "|" & Replace(arr(1, j), "表中的数值", "")
- If d.exists(s) Then
- arr = d(s)
- Next
- Next
- Next
- .Range("a1:f" & r) = arr
- End With
- Application.ScreenUpdating = True
- MsgBox "汇总完毕,共用时: " & Format(Timer - tm, "0.000秒"), , "提示"
- End Sub
复制代码
|
|