How to create a formula if with fix error in 0 divide 0

How to create a formula with 4 conditions.

I want to create:

=IF(B5<B6,B1+B2,B1/B2)

If my B1 or B2 is 0, it will show error #div0!

But I would like to remove that error with blank ""

How should I complete it ?


Simply create another IF statement in the else block of the first IF statement. This second IF will test if B2 is 0, in this case, output only the blank, if not, perform the division, like so:

=IF(B5<B6; B1+B2; IF(B2=0; ""; B1/B2))

Note that this always first checks if B5<B6, regardless of what B2 is. Only if B5 is greater than B6 it will check if B2 is 0. If it is, it outputs the blank "", if not, it performs the division.


I myself would use Obnebions answer if it was me putting together that formula, but here is an alternative for errors in general.

You can replace any error with IFERROR

So you would use :

=IFERROR( IF(B5<B6,B1+B2,B1/B2), "")

It works like this:

=IFERROR( *your formula here*,  *what you want if your formula returns an error*)

You can even use a completely different formula as the replacement.