Вы находитесь на странице: 1из 5

Excel IFERROR Function Example #1

For example, if A1 contains 10, B1 is blank, and C1 contains the formula


=A1/B1, the following formula will catch the #DIV/0! error that results
from dividing A1 by B1:

=IFERROR (A1/B1,"Please enter a value in B1")

As long as B1 is empty, C1 will display the message "Please enter a value


in B1" if B1 is blank or zero. When a number is entered in B1, the
formula will return the result of A1/B1.

Example #2

You can also use the IFERROR function to catch the #N/A error thrown
by VLOOKUP when a lookup value isn't found. The syntax looks like
this:
Summary 
=IFERROR(VLOOKUP(value,data,column,0),"Not found")
The Excel IFERROR function returns a custom result when a formula
generates an error, and a standard result when no error is detected. In this example, when VLOOKUP returns a result,  IFERROR
IFERROR is an elegant way to trap and manage errors without using
functions that result. If VLOOKUP returns #N/A error because a lookup
more complicated nested IF statements. value isn't found, IFERROR returns "Not Found". 
Purpose 
Trap and handle errors
Notes
Return value 
The value you specify for error conditions.
Syntax   If value is empty, it is evaluated as an empty string ("") and not
=IFERROR (value, value_if_error) an error.
Arguments   If value_if_error is supplied as an empty string (""), no message
 value - The value, reference, or formula to check for an error. is displayed when an error is detected.
 value_if_error - The value to return if an error is found.  If IFERROR is entered as an array formula, it returns an array of
Usage notes  results with one item for each cell in value.
The IFERROR function "catches" errors in a formula and returns an  In Excel 2013+, you can use the IFNA function to trap and handle
alternative result or formula when an error is detected. #N/A errors specifically.
Use the IFERROR function to trap and handle errors produced by other
formulas or functions. IFERROR checks for the following errors: #N/A,
#VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!.
The IFERROR function takes two arguments: a value (usually entered as
a formula), and a result to display if the formula returns an error. The
Basic error trapping example second argument is only used if the first argument throws an error.

In this case, the first argument is the simple formula for calculating the
average order size, which divides total sales by the order count:

=C5/D5

The second argument is entered as an empty string ("").


When the formula returns a normal result, the result is displayed.
When the formula returns #DIV/0!, an empty string is returned and
nothing is displayed.

Excel VLOOKUP Function

Generic formula 
=IFERROR(formula,value_if_error)

Explanation 

To catch errors that a formula might trigger in a worksheet, you can use
the IFERROR function to display a custom message, or nothing at all.

In the example shown, the formula in E5 is:

=IFERROR(C5/D5,"")

How this formula works

In this example, the IFERROR function is used to trap and suppress the
#DIV/0! error that occurs when there is no value for Orders (column D).
Without IFERROR, the formula C5/D5 would display a #DIV/0! error in
E6 and E9.
If you have data organized horizontally, use the HLOOKUP function.
Summary  VLOOKUP only looks right
VLOOKUP is an Excel function to lookup and retrieve data from a
specific column in table. VLOOKUP supports approximate and exact
matching, and wildcards (* ?) for partial matches. The "V" stands for VLOOKUP requires a lookup table with lookup values in the left-most
"vertical". Lookup values must appear in the first column of the table, column. The data you want to retrieve (result values) can appear in any
with lookup columns to the right. column to the right:
Purpose 
Lookup a value in a table by matching on the first column
Return value 
The matched value from a table.
Syntax 
=VLOOKUP (value, table, col_index, [range_lookup])
Arguments 
 value - The value to look for in the first column of a table.
 table - The table from which to retrieve a value.
 col_index - The column in the table from which to retrieve a
value.
 range_lookup - [optional] TRUE = approximate match (default).
FALSE = exact match. VLOOKUP retrieves data based on column number
When you use VLOOKUP, imagine that every column in the table is
Usage notes  numbered, starting from the left. To get a value from a particular column,
provide the appropriate number as the "column index". For example, the
VLOOKUP is designed to retrieve data in a table organized into vertical column index to retrieve first name below is 2:
rows, where each row represents a new record. The "V" in VLOOKUP
stands for vertical:
VLOOKUP has two matching modes, exact and approximate Example 2: Approximate match
VLOOKUP has two modes of matching: exact and approximate, which In cases when you want the best match, not necessarily an exact match,
are controlled by the 4th argument, called "range_lookup". Set you'll want to use approximate mode. For example, below we want to
range_lookup to FALSE to force exact matching, and TRUE for look up a commission rate in the table G5:H10. The lookup values come
approximate matching. from column C. In this example, we need to use VLOOKUP in
approximate match mode, because in most cases an exact match will
Important: range_lookup defaults to TRUE, so VLOOKUP will use never be found. The VLOOKUP formula in D5 is configured to
approximate matching by default: perform an approximate match by setting the last argument to TRUE:
=VLOOKUP(value, table, column) // default, approximate
match
=VLOOKUP(value, table, column, TRUE) // approximate
match
=VLOOKUP(value, table, column, FALSE) // exact match

Example 1: Exact match


In most cases, you'll probably want to use VLOOKUP in exact match
mode. This makes sense when you have a unique key to use as a lookup
value, for example, the movie title in this data:

=VLOOKUP(C5,$G$5:$H$10,2,TRUE) // TRUE = approximate match

VLOOKUP will scan values in column G for the lookup value. If an exact match
is found, VLOOKUP will use it. If not, VLOOKUP will "step back" and match
the previous row.

Note: data must be sorted in ascending order by lookup value when you use
approximate match mode with VLOOKUP.
VLOOKUP and #N/A errors
The formula in H6 to find Year based on an exact match of movie title is:
=VLOOKUP(H4,B5:E9,2,FALSE) // FALSE = exact match If you use VLOOKUP you will inevitably run into the #N/A error. The #N/A
error just means "not found". In practice, there are many reasons why you might
see this error. Among the most common:

 The lookup value does not exist in the table


 The lookup value is misspelled, or contains extra space The message can be customized as desired. To return nothing (i.e. to
display a blank result) when VLOOKUP returns #N/A you can use an
 Match mode is exact, but should be approximate
empty string like this:
 The table range is not entered correctly
=IFNA(VLOOKUP(H4,B5:E9,2,FALSE),"") // no message
 You are copying VLOOKUP, but the table reference is not locked
For example, in the example below, the lookup value "Toy Story 2" does not
exist in the lookup table, and all three VLOOKUP formulas return #N/A: Note: In many cases the #N/A is useful because it tells you something is
wrong.  Read more here about handling VLOOKUP #N/A errors 
Other notes

 Range_lookup controls whether value needs to match exactly or


not. The default is TRUE = allow non-exact match.
 Set range_lookup to FALSE to require an exact match and TRUE
to allow a non-exact match.
 If range_lookup is TRUE (the default setting), a non-exact match
will cause the VLOOKUP function to match the nearest value in the table
that is still less than value.
 When range_lookup is omitted, the VLOOKUP function will allow
a non-exact match, but it will use an exact match if one exists.
 If range_lookup is TRUE (the default setting) make sure that
One way to "trap" the NA error is to use the IFNA function: lookup values in the first row of the table are sorted in ascending order.
Otherwise, VLOOKUP may return an incorrect or unexpected value.
 If range_lookup is FALSE (require exact match), values in the first
column of table do not need to be sorted.

The formula in H6 is:

=IFNA(VLOOKUP(H4,B5:E9,2,FALSE),"Not found")

Вам также может понравиться