|
楼主 |
发表于 2020-9-25 22:27
|
显示全部楼层
Sub AwTest()
Dim i&, r&, s, arr, brr(1 To 5000, 1 To 2), ws As Worksheet
Application.DisplayAlerts = False '禁止弹出关对话框
For Each ws In Sheets
If ws.Name = "汇总" Then ws.Delete
Next
Application.DisplayAlerts = True
Sheets.Add.Name = "汇总"
[a1] = "表名": [b1] = "求和值"
For Each ws In Sheets
If ws.Name <> "汇总" Then
s = 0
arr = ws.[a1].CurrentRegion
For i = 2 To UBound(arr)
If Len(arr(i, 3)) Then s = s + arr(i, 3)
Next
r = r + 1
brr(r, 1) = ws.Name: brr(r, 2) = s
End If
Next
If r > 0 Then Sheets("汇总").[a2].Resize(r, 2) = brr
End Sub
想请教一下第二段标红为什么要这么写呢,还有想请教一下,如果我是好几列数据相加求和,那么第一句标红的要怎么修改呢,谢谢 |
|