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.
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Without seeing your actual code it is very difficult to help. Please post the actual code you are using.
 

avitas

New Member
Joined
Nov 3, 2010
Messages
3
Sub test()

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

ReturnVal = x / y
MyCheck = IsError(ReturnVal)

End Sub
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Why don't you just check if the divisor (in this case y) is zero before you do the division?
 

avitas

New Member
Joined
Nov 3, 2010
Messages
3
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.
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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.
 

Forum statistics

Threads
1,082,126
Messages
5,363,315
Members
400,725
Latest member
excelingtolearn

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top