test for #VALUE in vba

jdm21788

New Member
Joined
Jul 29, 2009
Messages
32
Hi folks,

I am getting a type mismatch on the following line of code:

Code:
If IsError(Cells(r, 4).Value + 1) And Cells(r, 5).Value <> "" Then

I have also tried:

Code:
If IsError(Cells(r, 4).Value + 1) = True And Cells(r, 5).Value <> "" Then

I want the If condition to be true if Cells(r, 4).Value + 1 = #VALUE and if Cells(r, 5).Value is not blank.

Thanks in advance!

Jonathan
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If Cells(r, 4).Value = #VALUE, you can't add 1 to an error.

I suggest doing your error check before adding 1

Damien
 
Upvote 0
Thanks for the responses, HOTPEPPER and dfenton21. The point of adding 1 is sort of an error check in itself. I am outputting into a template from SAS and it is automatically outputting either a 2 digit number or 2 blanks. By adding 1 to the blanks, it triggers the error. (I can't make the condition > 0 because the number is sometimes 0.) I found the solution, though, I was making it much more difficult than it needed to be. I simply look for the value to = " " or, in other words "_ _" / 2 blanks. Thanks again!
 
Upvote 0
dfenton21 is correct to do your error check before adding 1.

Please try and check if this does the same trick as you wanted.

Code:
If Application.WorksheetFunction.IsText(Cells(r, 4)) And Cells(r, 5) = "" Then

You can see that i have removed the ".value + 1" part of the statement because it is the cause of the error (as what dfenton21 said). Also, I have used the IsText (from HOTPEPPER's idea*) function since cells(r,4).value + 1 will trigger error only when it is not a number (I hope this is same with the criteria you need).

:) cheers!

-e.rgabrieldoronila

*but you can't use IsNumeric without using it as UDF. You can use IsNumber function instead.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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