我对VBA相当新,而且我找不到一种简单的方法来测试任何指定的变量是否等于指定的值。以下似乎有效,但有更简单的方法吗?
If variable1 = 1 Or variable2 = 1 Or variable3 = 1 Or variable4 = 1 Or variable5 = 1 Then End If
我也试过以下,没有运气。
If (variable1 Or variable2 Or variable3 Or variable4 Or variable5) = 1 Then End If
答案 0 :(得分:14)
您可以使用选择案例:)
Sub Sample()
Dim variable1, variable2, variable3, variable4, variable5
variable1 = 1: variable2 = 1: variable3 = 1: variable4 = 1: variable5 = 1
Select Case 1
Case variable1, variable2, variable3, variable4, variable5
MsgBox "One of them is equal to 1"
Case Else
MsgBox "none of then is equal to 1"
End Select
End Sub