【发布时间】:2015-08-13 21:28:00
【问题描述】:
我在使用 .Find 和 .FindNext 时遇到问题。我想准确搜索字符串“Q1”。目前,当我的 .FindNext 函数运行时,它会在一个以“Q10”为值的单元格中找到“Q1”。如何限制 .Find 和/或 .FindNext 函数来搜索我想要的确切字符串? 感谢您的帮助!
这是我的代码。例如,我想在可能具有 Q1、Q3、Q5、Q10、Q11、Q1、Q2、Q1 等的单元格范围内查找“Q1”的第三个实例。
Dim findValue As Range
' find first instance of Q1
searchString = "Q1"
Set findValue = ActiveWorkbook.Sheets("Sheet1").Cells.Find(What:=searchString)
findValue.select
' set loopMax to 2 because we want to .Findnext to run two more times to arrive at the third instance of "Q1"
For counter = 1 To loopMax
Set findValue = ActiveWorkbook.Sheets("Sheet1").Cells.FindNext(findValue)
findValue.select
Next counter
我被困住了。任何帮助将不胜感激!
【问题讨论】:
-
需要在您对
Find()的调用中添加lookat:=xlWhole -
老兄,谢谢!!你们是救生员。