Formula Errors

How to Get Rid of the #DIV/0! Error in Excel

Get rid of the #DIV/0! error in Excel by checking for blank or zero divisors, then choosing what the cell should show when there is nothing to divide.

On this page
  1. Why it happens
  2. Check the divisor
  3. Option 1: Show a blank
  4. Option 2: Show zero
  5. Option 3: Hide any error
  6. Averages and pivot tables
  7. Google Sheets

The #DIV/0! error appears when a formula tries to divide by zero. Excel treats an empty cell as zero in a division, so a blank divisor causes the same error. The fix has two parts: check whether the divisor should be zero, then decide what the cell should show when there is nothing to divide.

Why it happens

  • A zero or blank divisor. =B2/C2 returns #DIV/0! when C2 is zero or empty.
  • An average with no numbers. AVERAGE returns #DIV/0! when its range holds no numbers, such as only blank cells or text.
  • A ratio with a zero base. A percentage change or a share of a total divides by a value that can be zero.
  • An average with no matches. AVERAGEIF returns #DIV/0! when no cells meet its condition. For how AVERAGEIF handles conditions, see averageif formula in excel example.

Check the divisor

Click the cell, read the formula, and use Evaluate Formula on the Formulas tab to see what the divisor holds. Look for empty cells, zeros and text. A cell with only a space looks blank but isn’t. Dividing by it gives a different error, #VALUE!.

Option 1: Show a blank

=IF(C2=0,"",B2/C2)

In Excel, a blank cell compares equal to 0, so this one test covers both zero and empty cells.

The result is text, not a number. Later formulas that do arithmetic on this cell can return #VALUE!, although SUM and AVERAGE skip text inside a range. If the cell feeds other calculations, check those formulas after you make the change.

Option 2: Show zero

=IF(C2=0,0,B2/C2)

This keeps the cell numeric, so totals still work. The risk is that a missing value looks like a real zero. A margin with no cost data could show as 0%, which suggests the data was checked when it wasn’t.

Option 3: Hide any error

=IFERROR(B2/C2,"")

IFERROR hides the error whatever its cause, including problems you’d want to see. Use it when you’re sure the divisor is the only thing that can go wrong.

Averages and pivot tables

Check that the range holds numbers before averaging:

=IF(COUNT(B2:B20)=0,"",AVERAGE(B2:B20))

COUNT counts only numbers, so the formula returns a blank when the range holds none.

In a pivot table, a calculated field that divides one field by another can show #DIV/0! for groups where the divisor is zero. To change how error values appear, open PivotTable Options, go to the Layout & Format tab, and set “For error values show” to the text you want.

Google Sheets

Google Sheets shows #DIV/0! in the same situations, and the IF and IFERROR patterns work there too.

When the zero means something is wrong with the data, fix the data. A blank or zero is for the cases where an empty result is the correct answer.

The complete guide to formula errors

Excel Formula Error Messages Explained
Read the guide

Keep exploring

Guides from other topics

All topics →