Reputation: 103
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
.
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
.
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
Upvotes: 0
Views: 49
Reputation: 24386
Use parentheses when needed. These are your main 2 corrected if
conditions:
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
Upvotes: 2