Delete rows if value from cell is not in list Options

B

bony_tony

Hi,
Someone has given me the following code for my previous post.
But i'm getting an error. It's highlighting "Application", and says
"Expected: Then or GoTo"

firstRowFound = True
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 6 To lastRow
If Not Iserror Application.Match(Range("D" & i), _
Worksheets('All Invoices').Columns(4),0)) Then
If firstRowFound = True Then
Rows(i).Select
firstRowFound = False
Else
Union(Selection, Rows(i)).Select
End If
End If
Next i
Selection.Delete Shift:=xlShiftUp

It looks ok to me, there's a "Then" at the end of the statement....
Any ideas?

Tony
 
N

Norman Jones

Hi Tony,

Try replacing:
If Not Iserror Application.Match(Range("D" & i), _
Worksheets('All Invoices').Columns(4),0)) Then

with

If Not IsError(Application.Match(Range("D" & i).Value, _
Worksheets("All Invoices").Columns(4), 0)) Then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top