星期一, 九月 05, 2011

IFERROR Excel Formula – What is it, syntax, examples and howto

From Chandoo.org
IFERROR Excel Formula – What is it, syntax, examples and howto:

IFERROR Excel Formula - What is it, syntax, examples and howtoIf IFERROR() were to be a person, I would hug her so hard that Jo (my wife) would get in to a cat fight with her. I know many a woman (and man) who get in to a fight with Excel formulas often. But thankfully, we avoid that as IFERROR is not a real person. It is, however a darned useful formula.


Since I cannot hug a formula anymore than I can get my son to sit tight, I will go ahead and sing an ode to her, in my style – by writing about how useful and powerful IFERROR formula is.


What is IFERROR() Formula & How does it work?


Introduced since Excel 2007, IFERROR() formula checks a formula (or expression) and returns the value of formula if there is no error, otherwise a custom formula.


IFERROR Excel Formula - What is it, syntax, examples and howto - Chandoo.org
For eg:


=IFERROR(1/0,"Try splitting an atom instead!")


will give the message Try splitting an atom instead! because the expression 1/0 returns an error (DIV/0 error)


Where as,


=IFERROR(0/1,"Try splitting an atom instead!")


will give the value 0 since 0 divided by 1 is 0.


How does IFERROR help me?


Archimedes once said, “Give me enough data and a spreadsheet, I can make any formula return an error.”


May be he was too confident, but errors are everywhere. And that is why IFERROR is useful. It provides an elegant and simple way to tackle the errors in your workbook.


Several common uses of IFERROR are,



  1. 1. While writing lookup formulas like VLOOKUP, INDEX+MATCH it is common to search for values that do not exist in your data. You can wrap such formulas in IFERROR for peace of mind.
    Ex: =IFERROR(VLOOKUP(...),"Not found")

  2. 2. While using reference formulas like INDEX, OFFSET, frequently, we try to fetch the data that is not in the list of values. This returns #REF errors. You can fix them with IFERROR easily.
    Ex: =IFERROR(INDEX(...),"")

  3. 3. While using arithmetic, numeric expressions, usually we end up dividing by 0. You can fix such things by using IFERROR.
    Ex: =IFERROR(AVERAGE(...),"0") — Returns 0 when the list has zero values.


Things to keep in mind while IFERRORing:


Please note that IFERROR is oblivious to the type of error. That means, no matter what the error is (DIV/0, #NAME, #N/A, #REF… etc.), IFERROR treats all of them equally and shows the same value. In other words, IFERROR is like “Catch all” in programming world.


How to handle errors if you are using Excel 2003 or below?


In earlier versions of Excel, we have a formula called as ISERROR() that can check an expression or formula for error and return TRUE if so. This formula is not same as IFERROR, but we can use it along with IF() formula to get the same result. For eg.


=IF(ISERROR(VLOOKUP(...)),"Not found",VLOOKUP(...))


works same as, =IFERROR(VLOOKUP(...),"Not found")


Notice that the ISERROR approach evaluates VLOOKUP formula twice!.


Do you IFERROR?


To err is human, to IFERROR is awesome.


Ever since discovering the IFERROR feature in Excel 2007, I have been using it so often. I use it to keep my output sheets clean and my formulas simple.


What about you? Do you use IFERROR? What is your experience like? Would you also give it a hug? If so, would your spouse get in to a cat fight with it? If so can you post some pics of it on our facebook page?


Please share your experiences and tips on using IFERROR() thru comments.


Related awesomeness:


1. How to understand and handle Excel formula errors
2. Excel formulas not working? What to do?
3. Handling errors and 5 other tips for writing better VLOOKUP formulas




没有评论: