我有一个 Excel VBA 程序,可以循环访问数据表中的每一行数据。
我的目标是一旦 bool 值bFound
设置为True
就退出while循环。
我认为我的条件“Or bFound=True”可能不正确。
bFound = False
While Sheets("Data").Cells(iRow, 1) <> "" Or bFound = True
If Sheets("Data").Cells(iRow, 11) = Sheets("Data2").Cells(iRow, 1) Then
bFound = True
End If
iRow = iRow + 1
Wend
'exit loop after the boolean=true
最佳答案
使用Do ... Loop
和退出Do
bFound = False
Do While Sheets("Data").Cells(iRow, 1) <> ""
bFound = Sheets("Data").Cells(iRow, 11) = Sheets("Data2").Cells(iRow, 1)
If bFound Then Exit Do
iRow = iRow + 1
Loop
关于vba - 在 VBA/VBS 中退出 while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32797367/