LOOKUP function
The LOOKUP function in Excel is used to search for a value in a range or array and return a corresponding value from another range or array. It is one of the older lookup functions in Excel, but it is still useful in certain cases. The LOOKUP function can be used in two forms: Vector Form and Array Form.
Syntax:
LOOKUP(lookup_value, lookup_vector, [result_vector])
- lookup_value: The value you want to search for. It can be a number, text, or logical value.
- lookup_vector: A range or array containing the data you want to search for the
lookup_valuein. It must be a one-dimensional range or array (either a row or column). - [result_vector] (optional): A range or array that contains the data you want to return. The result vector must be the same size as the lookup vector. If omitted, the function returns the value from the lookup vector.
1. Vector Form:
In vector form, the LOOKUP function searches for a value in a single row or column and returns a corresponding value from another row or column. Here’s the basic form:
LOOKUP(lookup_value, lookup_vector, result_vector)
Example 1: Vector Form Suppose you have a list of product names in A1:A5 and their prices in B1:B5, and you want to find the price of a product named “Apple.”
| A | B |
|---|---|
| Apple | 1.5 |
| Banana | 0.8 |
| Grape | 2.0 |
| Orange | 1.2 |
| Mango | 1.8 |
Use the formula:
=LOOKUP("Apple", A1:A5, B1:B5)
This formula will return 1.5, the price of “Apple,” because it finds the position of “Apple” in A1:A5 and returns the corresponding value from B1:B5.
2. Array Form:
In array form, LOOKUP searches for a value in a range and returns a value from another column or row within the same range. This form can search in both horizontal and vertical arrays. The lookup vector must be in ascending order for the function to work properly in this mode.
LOOKUP(lookup_value, array)
Example 2: Array Form If you have an array like the following:
| A | B |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
| 5 | 50 |
You can use this formula:
=LOOKUP(3, A1:B5)
This formula will return 30, which is the value corresponding to 3 in the array A1:B5.
Important Notes:
- The
LOOKUPfunction requires thelookup_vectorto be sorted in ascending order for it to work correctly. - If the
lookup_valueis smaller than the smallest value in thelookup_vector, the function will return the first value in theresult_vector. - If the
lookup_valueis larger than the largest value in thelookup_vector, the function will return the last value in theresult_vector. - If an exact match for the
lookup_valueis not found, theLOOKUPfunction will approximate the result by returning the largest value that is less than or equal to thelookup_value.
Example 3: Approximate Match
In the following data, you can find the closest match for a value:
| A | B |
|---|---|
| 1 | 10 |
| 3 | 30 |
| 5 | 50 |
| 7 | 70 |
| 9 | 90 |
If you want to find the value in column B corresponding to 4 (a value that doesn’t exist), the formula:
=LOOKUP(4, A1:A5, B1:B5)
will return 30, the largest value less than or equal to 4 in the lookup_vector (A1:A5).
Benefits of the LOOKUP function:
- Simple Usage: It’s easy to use when you need to find a value from a range and return a corresponding value from another range.
- Works with Sorted Data: It works well when data is sorted in ascending order, especially for finding approximate matches.
- Compact Formula: It’s concise compared to other lookup functions like
VLOOKUPorHLOOKUP.
Use Cases:
- Price Lookup: If you have a price list in a table and want to look up prices based on a product name or code.
- Rankings: You can use
LOOKUPto find the rank of a specific score from a list of scores. - Grade Lookup: In academic settings, you can use
LOOKUPto assign a grade based on a numerical score.
Limitations:
- No Exact Match: Unlike
VLOOKUP,LOOKUPcannot return an exact match unless the data is sorted. If the value isn’t found, it returns an approximate match based on the largest value less than or equal to the lookup value. - Does Not Handle Errors Well: If the data isn’t sorted properly or the value is out of range, it can lead to incorrect results or errors.
Alternative Functions:
VLOOKUPandHLOOKUP: These functions are more powerful thanLOOKUPwhen working with data that isn’t sorted or when you need to handle exact matches more flexibly.INDEXandMATCH: A more advanced combination of functions,INDEXandMATCHallow for more control over data lookup and do not require sorted data.
In summary, the LOOKUP function in Excel is a simple and effective way to find values in a range or array and return corresponding values from another range. However, it is best suited for situations where data is sorted in ascending order and approximate matches are acceptable.