简体   繁体   English

复杂的IF条件,包括逻辑AND / OR

[英]Complicated IF condition including logical AND / OR

It runs but it does not do what it is supposed to do. 它可以运行,但没有执行应做的事情。 What I need: 我需要的:

If cell B contains "RR", and if cell C does not equal "memo" or "correction" and cell G is not "air" or "printed" then change cell L to 0 . 如果单元格B包含“ RR”,并且如果单元格C不等于“ memo”或“ correction”,并且单元格G 不是 “ air”或“ printed”,则将单元格L更改为0

If cell B contains "RR", and if cell C does not equal "memo" or "correction" and cell G is "air" or "printed" then change cell L to H*.1 . 如果单元格B包含“ RR”,并且如果单元格C不等于“备注”或“校正”,并且单元格G “空气”或“已打印”,则将单元格L更改为H*.1

Sub RRCLEAN()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim myString As String
With ActiveSheet
RowCount = WorksheetFunction.CountA(range("A:A"))

For i = 2 To RowCount
    myString = Trim(Cells(i, 2).Value)
    If InStr(myString, "RR") > 0 And .Cells(i, 3).Value <> "Memo" And .Cells(i, 3).Value <> "Correction" And .Cells(i, 7).Value <> "Air" Or .Cells(i, 7).Value <> "Printed" Then
        Cells(i, 12).Value = 0
    End If
Next

For i = 2 To RowCount
    myString = Trim(Cells(i, 2).Value)
    If InStr(myString, "RR") > 0 And .Cells(i, 3).Value <> "Memo" And .Cells(i, 3).Value <> "Correction" And .Cells(i, 7).Value = "Air" Or .Cells(i, 7).Value = "Printed" Then
        Cells(i, 12).Value = Cells(i, 8).Value * 0.1
    End If
Next
End With

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Use parentheses when needed. 必要时使用括号。 These are your main 2 corrected if conditions: if条件,这些是您要纠正的主要问题2:

If InStr(myString, "RR") > 0 And .Cells(i, 3).Value <> "Memo" And .Cells(i, 3).Value <> "Correction" And .Cells(i, 7).Value <> "Air" And .Cells(i, 7).Value <> "Printed" Then

If InStr(myString, "RR") > 0 And .Cells(i, 3).Value <> "Memo" And .Cells(i, 3).Value <> "Correction" And (.Cells(i, 7).Value = "Air" Or .Cells(i, 7).Value = "Printed") Then

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM