|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
参与一下。。。
- Sub ykcbf() '//2024.6.18
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("汇总")
- sh.[a:d].ClearContents
- p = ThisWorkbook.Path & "\新建文件夹"
- For Each f In fso.GetFolder(p).Files
- fn = fso.GetBaseName(f)
- m = m + 1
- Set Wb = Workbooks.Open(f, 0)
- With Wb.Sheets(1)
- r = IIf(m = 1, 1, sh.Cells(Rows.Count, 1).End(xlUp).Offset(2).Row)
- .UsedRange.Copy sh.Cells(r, 1)
- Wb.Close 0
- End With
- Next f
- With sh
- r = .Cells(Rows.Count, 2).End(3).Row
- arr = .[a1].Resize(r, 2)
- For i = 1 To UBound(arr)
- If arr(i, 1) = Empty And arr(i, 2) <> Empty Then
- arr(i, 1) = arr(i - 1, 1)
- End If
- s = arr(i, 2)
- d(s) = arr(i, 1)
- Next
- .[a1].Resize(r, 2) = arr
- r = .Cells(Rows.Count, "i").End(3).Row
- For i = 1 To r
- s = .Cells(i, "i")
- If d.exists(s) Then
- .Cells(i, "h") = d(s)
- End If
- Next
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "汇总完毕!"
- End Sub
复制代码
|
|