|
加上统计表计算:- Sub Macro1()
- Dim MyPath$, MyName$, sh As Worksheet, d As Object, arrsh, wb As Workbook, i&, t, arr(1 To 1000, 1 To 11), m&, rng As Range
- Application.ScreenUpdating = False
- Set d = CreateObject("scripting.dictionary")
- arrsh = Array("A6:L15", "A4:H14", "A5:H15", "A5:J16", "A4:H14")
- For i = 1 To Sheets.Count - 1
- If InStr(Sheets(i).Name, "附件") Then
- Sheets(i).Range(arrsh(i - 1)).Resize(1000).Clear
- d(Sheets(i).Name) = i
- End If
- Next
- Set wb = ThisWorkbook
- MyPath = ThisWorkbook.Path & ""
- MyName = Dir(MyPath & "*.xls")
- Do While MyName <> ""
- If MyName <> ThisWorkbook.Name Then
- m = m + 1
- arr(m, 1) = m
- arr(m, 2) = Replace(MyName, ".xls", "")
- arr(m, 3) = Split(MyName, "-")(0)
- arr(m, 4) = "姓名" & m
- arr(m, 5) = Split(arr(m, 2), "-")(2)
- With GetObject(MyPath & MyName)
- For Each sh In .Sheets
- t = d(sh.Name)
- If t <> "" Then
- Set rng = sh.Range(arrsh(t - 1))
- r = sh.[b65536].End(xlUp).Row - rng.Row + 1
- arr(m, 6) = arr(m, 6) + r
- arr(m, t + 6) = arr(m, t + 6) + r
- rng.Copy wb.Sheets(t).[a65536].End(xlUp).Offset(1)
- End If
- Next
- .Close False
- End With
- End If
- MyName = Dir
- Loop
- With Sheets("统计表")
- .Range("A4:K65536").ClearContents
- [a4].Resize(m, 11) = arr
- .[f3:k3].FormulaR1C1 = "=SUM(R4C:R" & m + 3 & "C)"
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|