Test if Cell range contains error

erock24

Well-known Member
Joined
Oct 26, 2006
Messages
1,161
I'm trying to test if a cell range that has a formula in it shows an error. I've tried this code:

Code:
If BudSht.Range("CheckValue") = Error Then Exit Sub

i'm getting a type mismatch debug, even though the cell range shows to have an 'Error 2023'

is there a way to test if a cell has an error in it in vba?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

PA HS Teacher

Well-known Member
Joined
Jul 17, 2004
Messages
2,838
Could you use a UDF such as:

<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Function</SPAN> HasError(Rng <SPAN style="color:#00007F">As</SPAN> Range) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN><br>   <SPAN style="color:#00007F">Dim</SPAN> C <SPAN style="color:#00007F">As</SPAN> Range<br>   <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> C <SPAN style="color:#00007F">In</SPAN> Rng.Cells<br>      <SPAN style="color:#00007F">If</SPAN> Application.WorksheetFunction.IsError(C) <SPAN style="color:#00007F">Then</SPAN> HasError = <SPAN style="color:#00007F">True</SPAN><br>   <SPAN style="color:#00007F">Next</SPAN> C<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN></FONT>
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,963
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I'm trying to test if a cell range that has a formula in it shows an error. I've tried this code:

Code:
If BudSht.Range("CheckValue") = Error Then Exit Sub
i'm getting a type mismatch debug, even though the cell range shows to have an 'Error 2023'

is there a way to test if a cell has an error in it in vba?
Code:
If IsError(BudSht.Range("CheckValue"))  Then Exit Sub
 

Forum statistics

Threads
1,176,151
Messages
5,901,642
Members
434,909
Latest member
subratgupta

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
Top