好吧,可能很简单,但我刚刚开始在这段代码中使用这种语言:
While DATA.Cells(1, i).value & "" <> ""
If InStr(DATA.Cells(1, i).value, columnName) > 0 Then
column = i
Exit While
End If
i = i + 1
Wend
看起来这不是使用 Exit While 的方法?那我该怎么办?
最佳答案
While/Wend
只能通过 GOTO
提前退出,或者通过从外部 block 退出(Exit sub
/函数
/另一个可退出循环
)
改为 Do
循环
Do While DATA.Cells(1, i).value & "" <> ""
If InStr(DATA.Cells(1, i).value, columnName) > 0 Then
column = i
Exit Do
End If
i = i + 1
Loop
来自 @Alex K 的原始答案。 Break out of a While...Wend loop in VBA
关于VBA : Exit While in If,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35012074/