![](/img/trans.png)
[英]Extract all Logical test condition used with IF statement (not nested) and print to separate column
[英]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.