ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete rows if value from cell is not in list Options (https://www.excelbanter.com/excel-programming/388634-delete-rows-if-value-cell-not-list-options.html)

bony_tony

Delete rows if value from cell is not in list Options
 
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


Norman Jones

Delete rows if value from cell is not in list Options
 
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


--
---
Regards,
Norman


"bony_tony" wrote in message
oups.com...
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





All times are GMT +1. The time now is 05:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com