繁体   English   中英

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

[英]Complicated IF condition including logical AND / OR

它可以运行,但没有执行应做的事情。 我需要的:

如果单元格B包含“ RR”,并且如果单元格C不等于“ memo”或“ correction”,并且单元格G 不是 “ air”或“ printed”,则将单元格L更改为0

如果单元格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

必要时使用括号。 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