I am totally new in macro's so I would like to know where did I make mistakes in my code.
I just want a simple IF - AND based on 2 different columns and the result should be in the third column
My code is:
Sub FTL_Customer3()
Lastrow = Sheets("Raw data").Range("D" & Rows.Count).End(xlUp).Row
For i = 1 To Lastrow
If Sheets("Raw data").Cells(i, 5) = "Postponed to next month" And Sheets("Raw
data").Cells(i, 13) = "ATP Ship date after EOM" Then
Cells(i, 7).Value = "OK"
End If
Next I
End Sub
CodePudding user response:
Ensure the cells you will be testing do not contain an error:
Sub FTL_Customer3()
With Worksheets("Raw data")
Dim LastRow As Long
LastRow = .Range("D" & .Rows.Count).End(xlUp).Row
Dim i As Long
For i = 1 To LastRow
If Not IsError(.Cells(i, 5)) And Not IsError(.Cells(i, 13)) Then
If .Cells(i, 5) = "Postponed to next month" And _
.Cells(i, 13) = "ATP Ship date after EOM" Then
.Cells(i, 7).Value = "OK"
End If
End If
Next i
End With
End Sub