|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
参与一下。。。
- Sub ykcbf() '//2024.9.29
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set fso = CreateObject("Scripting.FileSystemObject")
- p = ThisWorkbook.Path & ""
- Set sh = ThisWorkbook.Sheets("汇总")
- With sh
- c = .Cells(3, "XFD").End(1).Column
- For j = 4 To c
- s = .Cells(3, j).Value
- d(s) = j
- Next
- bt = .[b1].Value
- bm = CStr(.[b2].Value)
- End With
- ReDim brr(1 To 10000, 1 To 100)
- For Each f In fso.GetFolder(p).Files
- If LCase(f.Name) Like "*.xls*" Then
- If InStr(f, "~$") = 0 Then
- If InStr(f, ThisWorkbook.Name) = 0 Then
- Set wb = Workbooks.Open(f, 0)
- fn = fso.GetBaseName(f)
- With wb.Sheets(bm)
- r = .Cells(Rows.Count, 1).End(3).Row
- c1 = .Cells(1, "XFD").End(1).Column
- arr = .[a1].Resize(r, c1)
- End With
- wb.Close 0
- For I = 2 To UBound(arr)
- M = M + 1
- brr(M, 1) = fn
- brr(M, 2) = bm
- brr(M, 3) = M
- For j = 1 To UBound(arr, 2)
- s = arr(1, j)
- If d.exists(s) Then
- brr(M, d(s)) = arr(I, j)
- End If
- Next
- Next
-
- End If
- End If
- End If
- Next
- With sh
- .UsedRange.Offset(3).Clear
- With .[a4].Resize(M, c)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|