testing for #NA with VBA

G

Guest

I am using VBA to loop through a range and if the cell contains an Excel
generated "#NA" I want to skip executing the functions in the loop.

To test for the "NA" I have tried the following:

If ActiveCell.Offset(idx1, 0).Value <> "Error 2042" Then _
and
If ActiveCell.Offset(idx1, 0).Value <> "#NA" Then _

and both give a "Run-time error '13': Type mismatch".

How can I test for an Excel generated '#NA' in a cell?

TIA
Tim Kredlo
Exterior Wood, Inc
 
B

Bob Phillips

Hi Tim,

Try this

Dim fErr As Boolean
On Error Resume Next
fErr = ActiveCell.Value = CVErr(xlErrNA)
On Error GoTo 0
If fErr Then MsgBox "#N/A"


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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