|
Option Explicit
Sub test()
Dim ar, br, i&, j&, r&, strFileName$, strPath$, strFind$
If [C3].Value = Empty Then Exit Sub Else strFind = [C3].Value
Application.ScreenUpdating = False
With Worksheets(2)
.[A3].CurrentRegion.Offset(1).Clear
ar = .[A3].CurrentRegion.Value
ReDim ar(1 To 10 ^ 4, 1 To UBound(ar, 2)) As String
strPath = Left(ThisWorkbook.Path, InStrRev(ThisWorkbook.Path, "\")) & "数据库\Test\"
strFileName = Dir(strPath & "*.xls")
Do Until strFileName = ""
If strFileName <> ThisWorkbook.Name Then
With GetObject(strPath & strFileName)
br = .Worksheets(1).[A1].CurrentRegion.Value
For i = 1 To UBound(br)
If br(i, 6) = strFind Then
r = r + 1
For j = 1 To UBound(br, 2)
ar(r, j) = br(i, j)
Next j
End If
Next i
.Close False
End With
End If
strFileName = Dir
Loop
If r Then
.[A4].Resize(r, UBound(ar, 2)) = ar
.Activate
End If
End With
Application.ScreenUpdating = True
Beep
End Sub
|
|