为什么我的Excel VBA宏会崩溃?
所以我制作了一个Excel宏,当我试图运行它时,它总是崩溃。这是:为什么我的Excel VBA宏会崩溃?,vba,excel,Vba,Excel,所以我制作了一个Excel宏,当我试图运行它时,它总是崩溃。这是: 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 改变或改变到和
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
改变或改变到和。
循环需要停在某个地方,目前它正在进入一个无止境的循环。
请尝试下面的代码,让我知道这是你想要的,或者我理解你的要求不正确
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
如果result=fail或Cells2,j中的任何一个出现故障,则Do-While循环Do-While-result=fail或Cells2,j将运行
我想你的意思是一旦你到达一个空单元格,或者你得到result=pass,就退出循环。因此,您需要将Or更改为和:
你说的撞车到底是什么意思?它在哪一行崩溃?无限循环,因为递增的j在这两种情况下都必须是
Do While result = "fail" And Cells(2, j) <> " "
Do While result = "fail" And Trim(Cells(2, j)) <> ""