[英]How to perform multiple AND statement after THEN Statement
Sub Crons()
Dim s1 As Worksheet, s2 As Worksheet
Dim check1 As Boolean, check5 As Boolean, check10 As Boolean, flow As Boolean, speed As Boolean, motor_power As Boolean
Set s1 = ThisWorkbook.Worksheets(1)
Set s2 = ThisWorkbook.Worksheets(2)
check1 = s2.CHECKBOXES("Check Box 1").Value = xlOn
check5 = s2.CHECKBOXES("Check Box 5").Value = xlOn
check10 = s2.CHECKBOXES("Check Box 10").Value = xlOn
flow = s1.Range("B26").Value = "Flow(from fill level)"
speed = s1.Range("B24").Value = "Speed"
motor_power = s1.Range("B25").Value = "Motor Power"
If check1 Or _
((check10 Or check5) Or _
(flow Or speed) Or _
(motor_power)) Then
s1.Range("B30").Value = "Activate anomaly detection" And _
s1.Range("B31").Value = "Activate Operating hour" And _
s1.Range("B32").Value = "Activate cycle time"
Else
s1.Range("B30").Value = vbNullString And _
s1.Range("B31").Value = vbNullString And _
s1.Range("B32").Value = vbNullString
End If
End Sub
Just don't use AND
!只是不要使用
AND
!
If check1 Or _
((check10 Or check5) Or _
(flow Or speed) Or _
(motor_power)) Then
s1.Range("B30").Value = "Activate anomaly detection"
s1.Range("B31").Value = "Activate Operating hour"
s1.Range("B32").Value = "Activate cycle time"
Else
s1.Range("B30").Value = vbNullString
s1.Range("B31").Value = vbNullString
s1.Range("B32").Value = vbNullString
End If
You misunderstand the And
operator.您误解了
And
运算符。 It has two purposes:它有两个目的:
Or
you've used in your If
statement.If
语句中使用的Or
。 Whereas True Or False
equals True
, True And False
equals False
.True Or False
等于True
, True And False
等于False
。1
bits present in both operands.1
位组成的值。 For example, 14 And 7
= binary 1110 And 0111
= binary 0110
= 6.14 And 7
= 二进制1110 And 0111
= 二进制0110
= 6。 Trying to use it as a procedural statement ("do X, and then do Y") per your code is not only incorrect but makes no sense, since this is the ordinary behaviour of two statements in sequence.尝试根据您的代码将其用作过程语句(“做 X,然后做 Y”)不仅不正确而且没有意义,因为这是两个语句顺序的普通行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.