避免'没有下一个'End Sub

时间:2021-07-08 00:09:18

It would be very helpfully if some of the experts here help me with the problem: I have a loop to check zero values in range and the problem is I cant avoid the error 'for without next'. Maybe this is wrong construction for the for loop using End Sub ? Thank you.

如果这里的一些专家帮助我解决问题,那将是非常有帮助的:我有一个循环来检查范围内的零值,问题是我不能避免错误'没有下一个'。也许这是使用End Sub的for循环的错误构造?谢谢。

For Each c In Range("B4:H4")

     If c.Value = 0 Then MsgBox "Wrong record!", vbExclamation
     End Sub
Next c

1 个解决方案

#1


5  

Exit, not end.

退出,而不是结束。

For Each c In Range("B4:H4")

  If c.Value = 0 Then 
    MsgBox "Wrong record!", vbExclamation
    Exit Sub
  End If
Next c

However, it is generally best to work out a way to limit the number of points to exit.

但是,通常最好找出一种方法来限制退出的点数。

#1


5  

Exit, not end.

退出,而不是结束。

For Each c In Range("B4:H4")

  If c.Value = 0 Then 
    MsgBox "Wrong record!", vbExclamation
    Exit Sub
  End If
Next c

However, it is generally best to work out a way to limit the number of points to exit.

但是,通常最好找出一种方法来限制退出的点数。