ExcelCSE.com

Menu
  • Excel 101
  • Excel Functions
  • Excel Formula
  • Contact Us
How to Use Excel > Excel Formula > Excel Divide by Zero Error

Excel Divide by Zero Error

How to Solve Excel Divide by Zero Error
Table of contents :
  • Solution #1, using IF Function
  • Solution #2, using IFERROR Function
  • Solution #3, using AGGREGATE Function
  • Solution #4, using Array Formula
  • Which One is the Best Solution?
  • Practice File Download

Excel Divide by Zero

Pay attention to the data below. A store sells five products. The beginning stock of each product is 100 pcs. At the end of the month, the clerk calculates the end stock of each product (see column C) and the money earned for each product (see column D).

What is the selling price of each product and what is the average selling price for all products sold in that shop?

Excel Divide by Zero Error

To calculate the selling price, divide the money earned with the items sold.

The Formula

=D3/(B3-C3)

Do a copy (CTRL+C) in cell E3 the do a paste (CTRL+V) in range E4:E7.

The Result

Divide by Zero Excel

There is a divide by zero error in cell E5 (no items sold for product C).

***

To find out the average selling price of the five products, you can use the AVERAGE function.

The Formula

=AVERAGE(E3:E7)

The Result

Excel Avoid Divide by Zero

It turns out that the AVERAGE function also returns a divide by zero error. How to solve this problem? Errors in cell E5 cause the same error when calculating the average selling price.

Solution #1, using IF Function

This solution is used to avoid an excel divide by zero error from appearing, by modifying a formula that calculates the selling price. If the items sold are equal to 0, no need to do a division operation, otherwise do a division operation.

The Formula

=IF(B3-C3=0,"No Sales",D3/(B3-C3))

The Result

Excel Average Divide by Zero

If there are no sales, the formula above displays “No Sales”, you can choose other words, but don’t use a number (i.e., 0 or other numbers), because will affect the calculation of the average selling price.

When the formula for calculating the selling price is modified, a #DIV/0! error in cell E5 disappears. The same error in cell E9 also disappears, displays the average selling price for the five products.

Solution #2, using IFERROR Function

Just like solution #1, solution #2 avoid divide by zero error from appearing.

The Formula

=IFERROR(D3/(B3-C3),"No Sales")

The Result

Excel Divide by Zero

The result is the same as solution # 1, the divide by zero error disappears in cells E5 and E9.

Other alternatives, you can use the IF function and the ISERROR function, the results are the same.

The Formula

=IF(ISERROR(D3/(B3-C3)),"No Sales",D3/(B3-C3))

Solution #3, using AGGREGATE Function

Solution #3 is different from the two previous solutions. This solution lets the excel divide by zero error appear. Change the formula in cell E9 from the AVERAGE function to the AGGREGATE function.

The Formula

=AGGREGATE(1,6,E3:E7)

The Result

Excel Divide by Zero Error

The Excel divide by zero error still appears in cell E5, but cell E9 displays the correct average selling price.

The solution is in options argument; there are several choices, number 6 is “Ignore error values”, meaning if there is an error in range E3:E7 the AGGREGATE function will ignore it.

Solution #4, using Array Formula

Solution #4 is the same as solution #3, leaving the excel divide by zero error still there and modifying the formula to calculate the average selling price using an array formula.

The Formula

=AVERAGE(IFERROR(E3:E7,"No Sales"))

The formula above is an array formula. 
It must be ended by pressing the CTRL+SHIFT+ENTER key together.

The Result

Divide by Zero Excel

How does the array formula work?

Solution #4 uses the same function as solution #2, i.e., the IFERROR function and the AVERAGE function. Solution #2 uses the IFERROR function first to calculate the selling price of each product, then use the AVERAGE function to calculate the average selling price.

The array formula in solution #4 can combine both functions in one formula. To find out how does the formula works, edit the formula in cell E9.

Block the IFERROR function, then press the F9 key.

The IFERROR function changes to an array with 5 data 10, 12, “No Sales”, 14, 15. Compare this with the results of the IFERROR function in solution #2, can you find any differences? The result is the same. The five data are calculated by the AVERAGE function to get the average selling price.

Block the AVERAGE function, then press the F9 key. The result is the average selling price.

The animation below explains how array formula array work.

Excel Avoid Divide by Zero

Which One is the Best Solution?

If you want the excel divide by zero error does not appear, then use solution #1 or solution #2. Both return the same results. Which one is the best? It’s up to you, choose one for your solution.

If you want to keep the excel divide by zero error, then use solution #3 or solution #4. For me, solution #3 is easier; it’s only an Excel function with three arguments. Solution #4 is more complicated then solution #3; it involves two functions and an array formula. My advice is to use the AGGREGATE function.

When to choose an array formula compared to the AGGREGATE function?

The AGGREGATE function only provides 19 functions; if the desired function not in the list, then it’s time to use an array formula. Array formula able to use all functions that Excel has.

Practice File Download

Download File

Related Function

Function used in this article
  • Excel IF Function
  • Excel IFERROR Function
  • Excel AVERAGE Function
  • Excel AGGREGATE Function
Share
Tweet
Google+
Email
Prev Article
Next Article

Related Articles

How to Merge Cells in Excel
There are several ways to merge cells in excel, using …

How to Merge Cells in Excel

How to Do Multiplication in Excel
For example, there is data like the picture below, four …

How to Do Multiplication in Excel

How to Create a Formula in Excel
How to Create a Simple Formula in Excel To create …

How to Create a Formula in Excel

VLOOKUP NA Error
VLOOKUP NA error is the most common error when using …

VLOOKUP NA Error – Causes and Solutions

Excel provides three different functions to extract a day, month, …

How to Extract Day, Month and Year from Date in Excel

Tags:AGGREGATE Function Array Formula AVERAGE Function Divide by Zero Excel Excel Average Divide by Zero Excel Avoid Divide by Zero Excel Divide by Zero Excel Divide by Zero Error IF Function IFERROR Function

Categories

  • Excel 101
  • Excel Formula
  • Excel Functions

Recent Posts

  • Get the Original Price from Percentage Increase/Decrease
  • How to Add/Subtract Percentage in Excel
  • How to Extract Day, Month and Year from Date in Excel
  • How to Add Seconds, Minutes and Hours to a Time in Excel
  • How to Add Days, Weeks, Months and Years to a Date in Excel
  • How to Calculate Time Difference in Excel
  • Calculate Number of Days, Weeks, Months and Years Between Two Dates in Excel
  • Flash Fill Excel
  • Paste Special Excel
  • Excel TEXTJOIN Function
  • Excel CONCAT Function
  • Excel CONCATENATE Function
  • Excel REPLACE Function
  • Excel SUBSTITUTE Function
  • Excel REPT Function
  • Excel FIND Function
  • Excel SEARCH Function
  • Excel MID Function
  • Excel RIGHT Function
  • Excel LEFT Function

ExcelCSE.com

The Ultimate Guide How to Use Excel Better
Copyright © 2024 ExcelCSE.com
Contact Us - Privacy Policy - Sitemap | Theme by MyThemeShop.com

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh