我循环遍历数组中的项目raArray
,我想在表中查找这些项目。但是,我似乎无法让代码运行以找到数组元素的下一个结果FindNext
。要么我陷入无限的 Do 循环,要么当我将raArray.adress
与以下m_strAdress
进行比较时FindNext
,我在第二次找到搜索查询后退出循环。
我不太明白我做错了什么,而且https://learn.microsoft.com/en-us/office/vba/api/excel.range.findnext对我没有帮助。
Dim raArray as Range
Dim m_strAddress as String
dim wksDeviation as Worksheet
dim iC as Long
For iC = 1 To 51
Set raArray = wksDeviation.Range("E:E").Find(arrAllYield(1, iC - 1), LookIn:=xlFormulas, LookAt:=xlPart)
If raArray Is Nothing Then
Debug.Print arrAllYield(1, iC - 1) & " Nothing found"
Else
m_strAddress = raArray.Address
If Not raArray Is Nothing Then
Do
Set raArray = wksDeviation.Range("E:E").FindNext(wksDeviation.Range("E:E").Find(What:=arrAllYield(1, iC - 1), LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= False, SearchFormat:=False))
Loop While raArray.Address <> m_strAddress And Not raArray Is Nothing
End If
End If
Next iC
任何能指出我哪里做错了的指点我都非常感谢。我被难住了。