2
我今天遇到了这个有趣的问题。我在另一个循环内部有一个循环,两者都使用Find
用于不同的目的。会发生什么情况是在内部循环中使用Find
将外部循环中的Find
拧紧。我猜excel只保留一个搜索实例的内存。有没有办法解决这个问题,或者这是一个设计问题?VBA中的多个Range.Find()
这里是我的代码的一些缩写版本。
Sub Main()
'Some boring stuff
Set lst_rapports = Worksheets("mappingTRANSIT").range("lst_rapports")
Set first_result = lst_rapports.Find(rap_choisi)
Set active_result = first_result
Sheets("req01").Unprotect "shoobidoowap"
If Not first_result Is Nothing Then
' ...
Do
Sheets("req01").Select
' ...
For i = 0 To 4
Set rubrique_cell = range("E:E").Find(rub(i))
If Not rubrique_cell Is Nothing Then
' ...
End If
Next i
' Yet more boring stuff...
Set active_result = lst_rapports.FindNext(active_result)
Loop Until active_result.Address = first_result.Address
Else
MsgBox "Impossible de trouver """ & rap_choisi & """ !"
End If
Sheets("req01").Protect "shoobidoowap"
End Sub
请注意,在第二使用的.Find
for循环。
是否有某种方法可以保留某种临时变量中的第一个搜索并在此之后恢复它?
非常感谢。
我会尝试这个明天! – ApplePie