【问题标题】:Excel VBA finding an exact string using .Find and .FindNextExcel VBA 使用 .Find 和 .FindNext 查找精确字符串
【发布时间】: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
  • 老兄,谢谢!!你们是救生员。

标签: excel vba


【解决方案1】:

需要在调用 Find() 时添加 lookat:=xlWhole

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-14
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多