我有一个工作簿,每个工作簿有5张和500行。我想要一个宏,它可以搜索可能在工作簿中出现多次的字符串。请帮帮我。
此致 MDS
答案 0 :(得分:0)
找到字符串后你想要它做什么?非宏方法是编辑 - 查找并单击选项按钮。将“内部”设置为“工作簿”并单击“查找全部”。这将为您提供所有找到的字符串的列表。
如果你真的想要一个宏,这个将打印位置到立即窗口。
Sub FindAll()
Dim sh As Worksheet
Dim rFound As Range
Dim sFirst As String
Dim sWhat as String
sWhat = Application.InputBox("Search for:")
For Each sh In ThisWorkbook.Worksheets
Set rFound = sh.UsedRange.Find(sWhat, , xlValues, xlPart)
If Not rFound Is Nothing Then
sFirst = rFound.Address
Debug.Print rFound.Address(, , , True)
Do
Set rFound = sh.UsedRange.FindNext(rFound)
If rFound Is Nothing Then Exit Do
Debug.Print rFound.Address(, , , True)
Loop Until rFound.Address = sFirst
End If
Next sh
End Sub