Deleting rows with #N/A

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using Excel 97 and want to delete rows of data which have a value of
#N/A in them which is the result from a vlookup formula.

I am using the following code but it is debugging with Type mismatch!

For i = 2 To LastRow

Cells(i, 5).Select

If Cells(i, 5).Value = "#N/A" Then
ActiveCell.EntireRow.Select
Selection.EntireRow.Delete
End If
Next i

Can anyone help with a solution, please?
 
Mark

Why not autofilter on that and delete the visible rows.
--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 
Okay,

But the rows with this value in will change, how do you prevent the wrong
rows being deleted?

Mark
 
consider modifying your vlookup first I suggest using the
if iserror function in the lookup.
example below

=IF(ISERROR(VLOOKUP(#REF!,CSR,2,FALSE))=TRUE,0,VLOOKUP
(#REF!,CSR,2,FALSE))

in the event of a error ie.. #Name..#Ref, the lookup can
put in a value like xxxxx. From here it would be easy to
identify and remove all of the undesired rows via code you
have already written.

Regards,
 
Sub DeleteRows()
columns(5).SpecialCells(xlformulas,xlerrors).EntireRow.Delete
End Sub
 
I like Tom's suggestion best, but ...

If Cells(i, 5).Text = "#N/A" Then
or
if iserror(cells(i,5).value) 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

Back
Top