Excel VBA Find函数总在Findnext过后变成nothing, 查不到第二个目标

有下面的语句, 在Sheet A中的D列去找含有abc的单元格,如果找到了,则对该单元格做条件判断,如果不满足条件则查找下一个含有abc的单元格。
在Sheet A中的D列中有两个单元格含有abc,第一次查找顺利结束,但是每当执行完findnext过后,c1就变成nothing, 而不再进行查找,想请大家帮忙找下问题所在。 谢谢

On Error Resume Next

With Worksheets("A").Range("D:D")
Set c1 = .find("abc", LookIn:=xlValues)
If Not c1 Is Nothing Then
firstAddress = c1.Address
Do
If criterior_Check(currentRow, c1.Row, conType) Then
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Else
Set c1 = .FindNext(c1)
End If
Loop While Not c1 Is Nothing And c1.Address <> firstAddress
Else
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Exit Sub
End If
End With

明显的逻辑问题啊。
如果找到了,则对该单元格做条件判断,如果不满足条件则查找下一个含有abc的单元格。

如果找到了,则对该单元格做条件判断,做完条件判断也需要再查找下一个,跟你的这个条件是没有关系的。。
所以应该是:
Do
If criterior_Check(currentRow, c1.Row, conType) Then
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Set c1 = .FindNext(c1)
Else
Set c1 = .FindNext(c1)
End If
Loop While Not c1 Is Nothing And c1.Address <> firstAddress
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-05-28

2个问题

     Set c1 = .FindNext(c1)  改成 Set c1 = .FindNext(After:=c1)

    Loop While Not c1 Is Nothing And c1.Address <> firstAddress
    改成   Loop Until (c1 Is Nothing) Or (c1.Address=firstAddress)

追问

没用啊~执行完findnext过后还是nothing

追答

表发给我测试下+Q191180776

相关了解……

你可能感兴趣的内容

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