Search Not Just Numbers

Loading...

Wednesday, 27 July 2011

EXCEL TIP: Eliminating #DIV/0! and other errors automatically using ISERROR

Excel is great for being able to apply the same calculation consistently by simply copying the formula to all of the relevant cells, however often there are times where some of the data isn't how we would like it and the formula throws up an error.

The most common of these is the #DIV/0! error that Excel returns when trying to divide a number by zero. As Excel struggles with the concept of infinity it returns this error. A common situation where this occurs is in a Gross Margin Percentage calculation. We may have multiple products with sales and profit figures and a formula to calculate the margin as a percentage, i.e. profit/sales formatted as a percentage.

This will work fine until you come to a product with no sales where the formula will return #DIV/0!.

This can be addressed using a combination of the IF statement and ISERROR (note that in Excel 2007 and 2010 there is a combined function called IFERROR, however the solution proposed here will also work in earlier versions of Excel). If you need a refresher on how the IF statement works take a look at :


If cell A1 contains the Sales figure and B1, the Profit, then to show the Margin Percentage in C1, we would format it as a percentage and use the following formula:

=B1/A1

This will return the #DIV/0! if cell A1 is empty or zero.

The ISERROR function returns TRUE if its argument returns an error and FALSE if not, therefore

=ISERROR(B1/A1)

will return TRUE when this #DIV/0! would occur.

We also need to decide what we want to appear instead of the error. In this scenario, I usually show 0% which is what I have assumed for the example.

Using the ISERROR formula above as the condition for the IF statement, we can return zero if it is an error, or the original calculation otherwise. So C1 becomes:

=IF(ISERROR(B1/A1),0,B1/A1)

No more #DIV/0! errors!

A similar approach can be used for any other common errors, such as when a looked up value is not in the list.

If you enjoyed this post, go to the top left corner of the blog, where you can subscribe for regular updates and your free report. If you wish to help me to provide future posts like this, please consider donating using the button in the right hand column.

12 comments:

  1. I found this site following a link to the Index and Match tip. I have used index before, but looking forward to an apportunity to use Match. On this tip for ISERROR, I assume you have since found the IFERROR function that streamlines the If(ISERROR()) function. It uses the format of IFERROR(value,value_if_error). So you can say =iferror(a1/b1,0) and will return a 0 if a1/b1 produces and error.

    ReplyDelete
    Replies
    1. But as he stated, the if(ISERROR()) format is used, the formula can be used in newer versions of Excel, but can also be used in Excel 97/2000. The IFERROR() format is not available in Excel 97/2000 so if used will eliminate any chance of a coworker using Excel 2000 being able to use your spreadsheet file on his computer, and not all companies are consistent enough to upgrade ALL computer system software versions at the same time. The last place I was employed only had Excel 2000 available on the computer I used, but most of the front office computers had Excel 2010 installed and in use. This made it so many Excel spreadsheets somebody in the front office would create intending for me to use it on the computer in my area wouldn't work at all on my computer, but any spreadsheet application I wrote would load and run successfully on any computer in the front office.

      Delete
  2. Thanks for providing these tips for solving Excel problems and working as data management expert in Excel. Get here best paper writing service for solving your assignments and past papers for your study. I hope it will help you for web content writing too.

    ReplyDelete
  3. i prefer to anticipate the error so as not to miss something else that may be lurking
    in this case, i would avoid the #DIV/0! error by using:
      =IF(A1,B1/A1,0)
    then anything else that may be amiss will present itself
    (it's also shorter and makes fewer function calls)

    jim

    ReplyDelete
    Replies
    1. That's a nice one for #DIV/0!, and certainly better from a technical point of view. IFERROR has more general application.

      Delete
  4. Just wondering, from an Accounting perspective, what should a Gross Margin Percent be displayed as if the price is $0? 0%? -100% ? Something else?

    ReplyDelete
    Replies
    1. It's really up to you. 0%, or just a dash are both common.

      Delete
  5. Glen, I've been searching for a way to defeat the #DIV/0 error. But I can't figure out how to apply any of the solutions to my formula that is configured to create a ratio: =TEXT(B5/D5,"0")&":1" Any ideas on this?

    ReplyDelete
    Replies
    1. Have you tried:

      =IFERROR(TEXT(B5/D5,"0")&":1","Text you want to appear when there is an error")

      Delete
    2. That worked great! Thank you so much.

      Delete
  6. IF(ISERROR(B4*C4/D4),"",(E4*F4/G4),"",H4*I4/J4+K4*L4/M4
    where false formula please solve problem

    ReplyDelete
    Replies
    1. I'm not sure what you'e trying to do.
      From what I can understand:
      if (B4*C4/D4) is an error, you wish to return "", this leaves only one argument to enter in your IF statement - i.e. what you want it to return if it's not an error. You have the following:

      (E4*F4/G4),"",H4*I4/J4+K4*L4/M4

      which is 3 arguments without a bracket to close the IF.

      Delete