VBA:消息框显示,循环状态



我创建了VBA代码,该代码在满足某个条件时显示一个消息框。此 if 语句循环遍历确定的范围。但是,对于满足我的条件的每个单元格,都会显示消息框。有没有办法确保消息框只显示一次?

这是我的代码:

Private Sub Worksheet_Change(ByVal Target As Range)
For Each cell In Range("S194:BZ194")
    If cell.Value < 0 Then
MsgBox "Unrestricted cash cannot be less than zero (Row 194). Please lower the loan growth rate."
End If
Next
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
    For Each cell In Range("S194:BZ194")
        If cell.Value < 0 Then
            MsgBox "Unrestricted cash cannot be less than zero (Row 194). Please lower the loan growth rate."
            Exit For
        End If
    Next
End Sub

最新更新