|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub Macro1()
- Dim MyPath$, MyName$, sh As Worksheet, d As Object, arrsh, wb As Workbook, i&, t, col%, c As Range
- Dim arr(1 To 1000, 1 To 11), m&, rng As Range, arrt(), x As WorksheetFunction
- Application.ScreenUpdating = False
- Set d = CreateObject("scripting.dictionary")
- arrsh = Array("A6:L6", "A4:H4", "A5:H5", "A5:J5", "A4:H4")
- For i = 1 To Sheets.Count - 1
- If InStr(Sheets(i).Name, "附件") Then
- Sheets(i).Range(arrsh(i - 1)).Resize(1000, 26).Clear
- d(Sheets(i).Name) = i
- End If
- Next
- Set wb = ThisWorkbook
- Set x = WorksheetFunction
- 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 c = sh.UsedRange.Find("说明:", , , xlPart)
- If Not c Is Nothing Then
- l = c.Row - 1
- Else
- l = 1000
- End If
- Set rng = sh.Range(Left$(arrsh(t - 1), 4) & l)
- r = sh.[b65536].End(xlUp).Row - rng.Row + 1
- If r > 0 Then
- ReDim arrt(1 To r, 1 To 3)
- arr(m, 6) = arr(m, 6) + r
- arr(m, t + 6) = arr(m, t + 6) + r
- With wb.Sheets(t)
- lr = .[a65536].End(xlUp).Row + 1
- rng.Copy .[a65536].End(xlUp).Offset(1)
- For k = 1 To r
- arrt(k, 1) = arr(m, 3)
- arrt(k, 2) = "'" & Replace(sh.Name, "附件", "") & "-" & k
- arrt(k, 3) = arr(m, 3) & "-" & Replace(sh.Name, "附件", "") & "-" & k
- Next
- col = rng.Columns.Count + 4
- If x.CountA(.Columns(col)) = 0 Then
- .Cells(rng.Row, col).Resize(r, 3) = arrt
- Else
- .Cells(65536, col).End(xlUp).Offset(1).Resize(r, 3) = arrt
- End If
- End With
- End If
- 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
复制代码 |
|