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

2025-03-20 15:01:31
推荐回答(2个)
回答1:

明显的逻辑问题啊。
如果找到了,则对该单元格做条件判断,如果不满足条件则查找下一个含有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

回答2:

2个问题

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

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