VBA:退出时如果

好吧,可能是一个简单的,但我只是开始使用这种语言,在这段代码:

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或者从一个外部块Exit subExit sub / function / another exitable loop

更改为Do循环intead

 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.的原始答案。 突破一个While … Wend循环在VBA中