The problem here is when any of the VLookups return an error then the If statements will fail with a runtime error.
That is caused by trying a comparison between an actual value and an error value.
I added the If Not(IsError(a) Or ... to avoid that error.
I've changed the code, and it now gives the result you posted in post #8.
Sub Code()
Dim totalrows As Long
Dim i As Long
Dim a As Variant
Dim b As Variant
Dim c As Variant
Sheets("Notifications").Cells.Clear
totalrows = Sheets("Data").UsedRange.Rows.Count
i = 1
For x = 1 To totalrows
If Sheets("Data").Cells(x, 1).Value = 0 Then
a = Application.VLookup(Sheets("Data").Cells(x, 2) & "ABC", Sheets("Data").Columns("A:I"), 9, False)
b = Application.VLookup(Sheets("Data").Cells(x, 2) & "DEF", Sheets("Data").Columns("A:I"), 9, False)
c = Application.VLookup(Sheets("Data").Cells(x, 2) & "GHI", Sheets("Data").Columns("A:I"), 9, False)
a = IIf(IsError(a), "", a)
b = IIf(IsError(b), "", b)
c = IIf(IsError(c), "", c)
If a > 30 Or b > 30 Or c > 30 Then
If a < 30 Or b < 30 Or c < 30 Then
Sheets("Notifications").Cells(i, 1) = Sheets("Data").Cells(x, 2)
i = i + 1
End If
End If
End If
Next x
End Sub
[/code]
Bookmarks