|
参与一下。。。
- Sub ykcbf() '//2024.4.23
- Dim fds As New Collection
- Set fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- Dim tm: tm = Timer
- Set sh = ThisWorkbook.Sheets("合并")
- p = ThisWorkbook.Path & "\各单位报表"
- getfds p, fds
- ReDim brr(1 To 10000, 1 To 100)
- n = 3: m = 1
- brr(1, 1) = "月份": brr(1, 2) = "文件名": brr(1, 3) = "表名"
- For Each fd In fds
- p1 = p & fd & ""
- For Each f In fso.GetFolder(p1).Files
- If f.Name Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- For Each sht In wb.Sheets
- With sht
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(r, c)
- bm = .Name
- End With
- For j = 1 To UBound(arr, 2)
- s = arr(1, j)
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- brr(1, n) = s
- End If
- Next
- For i = 2 To UBound(arr)
- m = m + 1
- brr(m, 1) = fd
- brr(m, 2) = fn
- brr(m, 3) = bm
- For j = 1 To UBound(arr, 2)
- c = d(arr(1, j))
- brr(m, c) = brr(m, c) + arr(i, j)
- Next
- Next
- Next
- wb.Close False
- End If
- End If
- Next f
- Next
- With sh
- .Cells.Clear
- Set Rng = .[a1].Resize(m, n)
- .[a1].Resize(1, n).Interior.Color = 49407
- With Rng
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .EntireColumn.AutoFit
- End With
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
评分
-
2
查看全部评分
-
|