How do I avoid errors when dividing by zero?
Test for zero with IF, or catch the error with IFERROR. A blank result is often clearer than 0, because 0 can look like a real answer.
ErrorsBeginner5 minExcel · Google Sheets
Example content. The numbers are fictional and made for learning.
Answer
Dividing by an empty cell or by 0 produces a divide-by-zero error in both Excel and Google Sheets. Put the numerator in A2 and the denominator in B2. With 10 and 2, the quotient is 5. With 10 and 0, the division is an error.
IF checks the denominator before dividing. When B2 is 0, the formula returns a blank. Otherwise it divides. This leaves other errors visible, which is useful when you only want to handle a zero.
IFERROR lets the division run, then replaces any error with the fallback you provide. A blank fallback hides the divide-by-zero error and also hides other problems, such as a text value in a number cell. Use it when a blank is acceptable. Returning 0 instead of a blank can look like a real quotient.
IF and IFERROR are English function names. The comma in each formula is the English argument separator. Both change with the spreadsheet language and regional settings. The formula pages list the usual names.
Return a blank when the denominator is zero.
English reference form
=IF(B2=0,"",A2/B2)This spelling uses English function names and commas between arguments. It is the reference form on this site, not the only spelling. A Swedish spreadsheet, for example, uses different function names and usually a semicolon. Cell names such as B2 stay the same.
See function names by languageParts of the formula
IFThe English name of the test function. It is not the name in every spreadsheet.
B2=0The test: the denominator is zero.
""A blank result when the test is true.
A2/B2The division when the denominator is not zero.
Return a blank when the division is any error.
English reference form
=IFERROR(A2/B2,"")This spelling uses English function names and commas between arguments. It is the reference form on this site, not the only spelling. A Swedish spreadsheet, for example, uses different function names and usually a semicolon. Cell names such as B2 stay the same.
See function names by languageParts of the formula
IFERRORThe English name. It catches the error after the calculation runs.
A2/B2The division to try.
""The fallback shown when that division is an error.