|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub test()
Dim Dic, Wb As Workbook, Ws As Worksheet, Arr, N&, FN$, Str$, Rng As Range, Str2$
Set Dic = CreateObject("scripting.dictionary")
Str = InputBox("查找内容:", "输入")
If Str = "" Then Exit Sub
Application.ScreenUpdating = False
FN = Dir(ThisWorkbook.Path & "\*.xls*")
Do While FN <> ""
If FN <> ThisWorkbook.Name Then
Set Wb = GetObject(ThisWorkbook.Path & "\" & FN)
With Wb
For Each Ws In .Worksheets
With Ws
If WorksheetFunction.CountIf(.Cells, “*" & Str & "*") <> 0 Then
Set Rng = .[a1]
Do While .Cells.Find(Str, Rng).Row > Rng.Row Or .Cells.Find(Str, Rng).Column > Rng.Column
Set Rng = .Cells.Find(Str, Rng)
Str2 = Left(Wb.Name, InStrRev(Wb.Name, ".") - 1) & vbTab & Ws.Name & vbTab & Replace(Rng.Address, "$", "") & vbTab & Rng.Value & vbTab & Rng.offset(0,2).value
If Not Dic.exists(Str2) Then Dic.Add Str2, ""
Loop
End If
End With
Next Ws
End With
Wb.Close False
End If
FN = Dir
Loop
Set Wb = Nothing
With Worksheets("查询")
.Rows("3:" & .Rows.Count).Clear
If Dic.Count > 0 Then
Arr = Dic.keys
For N = LBound(Arr) To UBound(Arr)
.Cells(N + 3, 1) = N + 1
.Cells(N + 3, 2).Resize(1, 5) = Split(Arr(N), vbTab)
Next N
.[a3].Resize(N, 6).Borders.LineStyle = 1
End If
End With
Set Dic = Nothing
Application.ScreenUpdating = True
MsgBox "查找完成"
End Sub
这样看一下会不会出现备注里你要的内容
注:后期的更改基本都是直接在这里改的,所以可能会有全角的符号,改成半角的基本就能正常了 |
|