|
多工作簿单条件合并。- Sub ykcbf() '//2024.7.12
- Set fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- Set sh = ThisWorkbook.Sheets("数据")
- With sh
- st = CStr(.[b5].Value)
- For j = 1 To 6
- d(.Cells(11, j).Value) = j
- Next
- End With
- ReDim brr(1 To 10000, 1 To 6)
- p = ThisWorkbook.Path & "\数据"
- On Error Resume Next
- For Each f In fso.GetFolder(p).Files
- If LCase$(f.Name) Like "*.xls*" Then
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- .AutoFilterMode = False
- arr = .UsedRange
- wb.Close False
- End With
- For i = 4 To UBound(arr)
- If CStr(arr(i, 2)) = st Then
- m = m + 1
- For j = 1 To UBound(arr, 2)
- s = arr(1, j)
- brr(m, d(s)) = arr(i, j)
- Next
- End If
- Next
- End If
- Next f
- With sh
- .[a12:f10000] = ""
- .[a12].Resize(m, 6) = brr
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|