How to detect #N/A using VBA

hh

New Member
Joined
Feb 12, 2004
Messages
22
Hi all,

I am using VBA to construct a spreadsheet for a user to analyse data. The user pastes data exported from two host systems, and I build formulae to harmonise the data (date formats, etc.). In one sheet I create vlookup formulae between the two sheets, and there are always a lot of #N/As. I would like to give the user the option to delete these rows, but I can't seem to trap these.

Some sample code:

Sub FormatSheet()

Application.ScreenUpdating = False

Dim rng As Range, rng2 As Range
Dim lastrow As Long

Set rng = Range("D65536").End(xlUp)
Do Until rng.Row = 5
Set rng2 = rng.Offset(-1)
If rng.Offset(0, 7) = "#N/A" Then rng.EntireRow.Delete
Set rng = rng2
Loop

End sub

I've tried all sorts of weird constructs using Iserror, but all to no avail.

:oops:

As always, any help will be greatly appreciated,

hh
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
This works for me;

Code:
If WorksheetFunction.IsNA(rng.Offset(0, 7)) Then rng.EntireRow.Delete
 
Upvote 0
Tried to adapt this to your needs. Test it and see if it works.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> FormatSheet()
    <SPAN style="color:#00007F">Dim</SPAN> rng <SPAN style="color:#00007F">As</SPAN> Range

    <SPAN style="color:#00007F">Set</SPAN> rng = Range(Range("K6"), Range("D65536").End(xlUp).Offset(0, 7))
    rng.SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
    <SPAN style="color:#00007F">Set</SPAN> rng = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0
Guys,

thanks for your help with this - your solutions worked a treat.

hh
 
Upvote 0

Forum statistics

Threads
1,217,086
Messages
6,134,477
Members
449,874
Latest member
Cl2130

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top