Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

>Solution :

Just don’t use AND!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading