Test for Error 2042?

GBagley

Board Regular
Joined
Feb 8, 2011
Messages
84
I've gathered that Error 2042 is the VBA equivalent of #N/A. How do I check for this? I have a worksheet that has a number of formulas that occasionally return #N/A. These have been converted their text values, but I can't seem to get my VBA code to recognize this. I always get a type mismatch.

Code:
If cell.offset(0, 12) = "Error 2042" Then 
...
If cell.offset(0, 12) = "" Then 
...
If cell.offset(0, 12) = "#N/A" Then 
...


None of these work. How do I trap these values in an If statement without modifying all my worksheet formulas? I would like to avoid using something like worksheetfunction.isna
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Code:
if range("a1").value = cverr(xlerrna) then

or

Code:
if worksheetfunction.isna(range("a1").value) then

or, more broadly,

Code:
if iserror(range("a1").value) then
 
Upvote 0
Hello,
You can check cell.text, text property will return #N/A and any other text shown in cell.
VBA Code:
debug.print cell.Text
#N/A
VBA Code:
debug.print cell.Value
Error 2042

Good luck
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,656
Members
449,091
Latest member
peppernaut

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