|
- Sub ykcbf() '//2025.3.25 多文件排重汇总
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- p = ThisWorkbook.Path & ""
- Set Sh = ThisWorkbook.Sheets("人数1")
- ReDim brr(1 To 10000, 1 To 100)
- m = 1: n = 1
- brr(1, 1) = "月份"
- Dim tm: tm = Timer
- On Error Resume Next
- For Each fd In fso.GetFolder(p).SubFolders
- m = m + 1
- brr(m, 1) = fd.Name
- For Each f In fso.GetFolder(fd).Files
- If LCase$(f.Name) Like "*.xls*" Then
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- arr = .UsedRange
- r1 = .Cells(Rows.Count, 1).End(3).Row
- For j = 2 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
- c = d(arr(1, j))
- brr(m, c) = brr(m, c) + Application.Sum(.Cells(3, j).Resize(r1 - 2))
- Next
- End With
- wb.Close 0
- End If
- Next
- Next
- With Sh
- .UsedRange.Clear
- .Cells.Interior.ColorIndex = 0
- .[a1].Resize(1, n).Interior.Color = 49407
- .[a2].Resize(m - 1, 1).Interior.Color = 5296274
- With .[a1].Resize(m, n)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- End With
- Application.ScreenUpdating = True
- MsgBox "共用时:" & Format(Timer - tm, "0.000") & "秒!"
- End Sub
复制代码
|
|