|
类似下面这样子,这个是工作表循环
Dim d As Object
Dim i As Long
Dim s As String
Dim sh As Worksheet
On Error Resume Next
Sheets.Add after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ActiveSheet.Name = "汇总"
Set d = CreateObject("Scripting.Dictionary")
For Each sh In Worksheets
t = sh.Name
arr = Sheets(t).Range("A1").CurrentRegion
If sh.Name <> "汇总" Then
For i = 4 To UBound(arr)
s = arr(i, 2)
If s <> "" Then
If d.Exists(s) Then
d(s) = d.Item(s) + arr(i, 32)
Else
d(s) = arr(i, 32)
End If
End If
Next
End If
Next
Sheets("汇总").Range("A1") = "姓名"
Sheets("汇总").Range("B1") = "合计"
Sheets("汇总").Range("A2").Resize(d.Count, 1) = WorksheetFunction.Transpose(d.keys)
Sheets("汇总").Range("B2").Resize(d.Count, 1) = WorksheetFunction.Transpose(d.Items) |
|