复杂的 IF 条件,包括逻辑 AND / OR
Complicated IF condition including logical AND / OR
它可以运行,但没有执行它应该执行的操作。我需要什么:
如果单元格 B 包含 "RR",并且如果单元格 C 不等于 "memo" 或 "correction" 并且单元格 G 不等于 "air" 或 "printed" 然后将单元格 L 更改为 0
.
如果单元格 B 包含 "RR",并且如果单元格 C 不等于 "memo" 或 "correction" 并且单元格 G 是 "air" 或 "printed" 然后将单元格 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
需要时使用括号。这些是您的主要 2 个更正 if
条件:
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
它可以运行,但没有执行它应该执行的操作。我需要什么:
如果单元格 B 包含 "RR",并且如果单元格 C 不等于 "memo" 或 "correction" 并且单元格 G 不等于 "air" 或 "printed" 然后将单元格 L 更改为 0
.
如果单元格 B 包含 "RR",并且如果单元格 C 不等于 "memo" 或 "correction" 并且单元格 G 是 "air" 或 "printed" 然后将单元格 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
需要时使用括号。这些是您的主要 2 个更正 if
条件:
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