|
- Private Sub Worksheet_Change(ByVal Target As Range)
- If Target.Address <> "$B$1" Then Exit Sub
- Dim br(), ar, i%, j%, n&, fn$, ipath$
- Application.ScreenUpdating = False
- w = Target.Value
- ipath = ThisWorkbook.Path & ""
- fn = Dir(ipath & "*.xls?")
- Do
- If Not fn Like ThisWorkbook.Name Then
- With Workbooks.Open(ipath & fn)
- For Each sht In .Worksheets
- ar = sht.Range("a3:i" & sht.[a65536].End(3).Row)
- For i = 1 To UBound(ar)
- If InStr(ar(i, 2), w) > 0 Then
- n = n + 1
- ReDim Preserve br(1 To 10, 1 To n)
- br(1, n) = sht.Name
- For j = 1 To 9
- br(1 + j, n) = ar(i, j)
- Next
- End If
- Next
- Next
- .Close False
- End With
- End If
- fn = Dir
- Loop While fn <> ""
- [a3:j65536] = ""
- [a3].Resize(n, 10) = Application.Transpose(br)
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|