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
CodePudding user response:
Just don't use 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
CodePudding user response:
You misunderstand the And
operator. It has two purposes:
- A logical operator, similar to the
Or
you've used in yourIf
statement. WhereasTrue Or False
equalsTrue
,True And False
equalsFalse
. - A bitwise operator, taking two integer operands and returning a value consisting of the
1
bits present in both operands. For example,14 And 7
= binary1110 And 0111
= binary0110
= 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.