|
改一下,适用多文件情况- Sub ykcbf() '//2024.12.5
- Application.ScreenUpdating = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- p = ThisWorkbook.Path & ""
- Set sh = ThisWorkbook.Sheets("明细")
- arr = sh.UsedRange
- c = sh.UsedRange.Columns.Count
- ReDim brr(1 To 10000, 1 To UBound(arr, 2))
- For j = 2 To UBound(arr, 2)
- s = arr(1, j)
- d(s) = j
- Next
- For Each f In fso.GetFolder(p).Files
- If LCase$(f.Name) Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(r, c)
- End With
- wb.Close 0
- For i = 2 To UBound(arr)
- m = m + 1
- brr(m, 1) = m
- For j = 1 To UBound(arr, 2)
- s = arr(1, j)
- For Each k In d.keys
- If InStr(s, k) Then
- brr(m, d(k)) = arr(i, j)
- Exit For
- End If
- Next
- Next
- Next
- End If
- End If
- Next
- With sh
- .UsedRange.Offset(1).ClearContents
- .[a2].Resize(m, c) = brr
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|