If(ISERROR

avitas

New Member
Joined
Nov 3, 2010
Messages
3
Hi - I can't seem to get the ISERROR to work in VBA.
Numerator = X
Denominator = Y
Fraction = X/Y

X and Y varies in my macro (loops through loads of data). Sometimes Y will be zero and my macro fails.

I want to apply the IF(ISERROR function: Fraction = IF(ISERROR((X/Y),0,(X/Y)). But I only get run-time error or Division by zero error message.

Does this only work if you actually have a "physical" cell in a sheet that calculates X/Y returning #DIV/0! evaluated to TRUE using ISERROR? Or should it be possible using "virtual" variables in VBA too? (X and Y reads from a sheet but X/Y is not in my sheet, only a line of code in my modul. Thanks.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Sub test()

Dim ReturnVal, MyCheck
Dim x, y
x = 10
y = 0

ReturnVal = x / y
MyCheck = IsError(ReturnVal)

End Sub
 
Upvote 0
I guess I could but there's already 2 IF's in my code screening numerators and denominators according to certain criteria leading to the division and I just find it harder to follow my own code. There's always workarounds byt it annoys me I know there's functionality that I can't get to work. But I guess as long as the division (ReturnVal) is only a variable in my code and not a calculation in a cell the IsError doesn't seem to work.
 
Upvote 0
I believe IsError identifies if the CVerr function has been used to assign an error value to a variable. As far as I know it doesn't identify that an expression (such as 1/0) will return an error.
 
Upvote 0

Forum statistics

Threads
1,214,863
Messages
6,121,978
Members
449,058
Latest member
oculus

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