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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

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