How to test if a cell contains an error using VBA

Alex Italo

New Member
Joined
Nov 19, 2004
Messages
4
Hello,

I use a VBA code to clear rows that have an specific field equal to zero.
Example: If cell D11 = 0 then the contents of all cells in row 11 are deleted.

The code goes like this:

If Sheets("WKST").Range("D11").Value = 0 Then
Sheets("WKST").Range("D1:D20").ClearContents
End If

The problem is that D11 may contain an error (like #DIV!0), since its value is calculated by a formula and the macro stops when the cell has an error accusing "incompatible types".

I can't include another IF function in the cell 'cause there are already too many nested IF's and the formula is so big that I almost used all space available.

I would like to know how to test the contents of a cell using VBA to know if there is an error.

Any help would be appreciated!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
alex.

you might try the VBA command IsError. you can reference it in the helpfile under Contents->VB Language Reference->Functions->H-L->IsError

ben.
 
Upvote 0

Forum statistics

Threads
1,222,552
Messages
6,166,744
Members
452,067
Latest member
rwsouth

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