为什么我的Excel VBAmacros崩溃?
所以我做了一个Excelmacros,当我尝试运行它,它不断崩溃。 这里是:
result = "fail" j = 4 Do While result = "fail" Or Cells(2, j) <> " " If Cells(2, j).Value >= 15 Then result = "pass" Else j = j + 1 End If Loop
如果Do While result = "fail" Or Cells(2, j) <> " "
则Do While
循环Do While result = "fail" Or Cells(2, j) <> " "
Cells(2, j) <> " "
。
我想你打算退出循环,一旦你到达一个空的单元格,或者你得到result = "pass"
。 所以,你需要改变你的Or
:
Do While result = "fail" And Cells(2, j) <> " "
如果要在单元格中只有空白的情况下退出,请添加“ Trim
。
Do While result = "fail" And Trim(Cells(2, j)) <> ""
改变或与。 循环需要停止某个地方,目前正在进入一个无限循环。 请尝试下面的代码,让我知道如果这是你想要的或我已经不正确地理解你的要求。
Sub tester() result = "fail" j = 4 Do While result = "fail" And Cells(2, j) <> "" If Cells(2, j).Value >= 15 Then result = "pass" Else j = j + 1 End If Loop End Sub