vba问题用VBA搜索最快的方法及语句,完整的搜索整个工作簿

如题所述

试试这个代码吧:
Sub 查找()
s = InputBox("输入要查找的内容") '数值或字符都可以
For i = 1 To Sheets.Count
With Worksheets(i).UsedRange '查找范围是每个工作表的已用区域
Set a = .Find(s, LookIn:=xlValues, LookAt:=xlWhole)
If Not a Is Nothing Then
h = a.Address
Do
Set a = .FindNext(a) '继续
b = b & "表" & i & a.Address & ";"
Loop While a.Address <> h
End If
End With
Next
If b = "" Then
MsgBox "没找到"
Else
MsgBox b
End If
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-09-11
Sub Macro1()
Dim bk As Workbook, sh As Worksheet, c As Range, msg$, s$, tmp
Set bk = ActiveWorkbook '接受搜索的工作薄
s = "a1" '搜索的字符
For Each sh In ActiveWorkbook.Worksheets
Set c = sh.Cells.Find(s, , xlValues, xlWhole) '匹配单元格的值、整个单元格匹配
If Not c Is Nothing Then
sh.Activate
c.Select
tmp = sh.Name & "!" & c.Address(0, 0)
MsgBox tmp
msg = msg & vbCrLf & tmp
End If
Next
If msg <> "" Then
MsgBox "找到以下单元格:" & vbCrLf & msg
Else
MsgBox "没有匹配的单元格!"
End If
End Sub本回答被提问者采纳
第2个回答  2011-07-28
for a=1 to 255
for b=1 to 65535
sheet_工作表名 .cells(a,b).value="你要找的东东"
msgbox “在" & a & "行 " & b & "列"。
next b
next a
第3个回答  2011-07-28
用FIND函数!

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网