How to Use IFERROR with VLOOKUP in Google Sheets
Using IFERROR with VLOOKUP in Google Sheets is a useful way to handle cases where the VLOOKUP function returns an error, such as when a value is not found in the specified range. This combination allows you to display a custom message or value when an error occurs, instead of displaying the default error message.
Here is a step-by-step guide on how to use IFERROR with VLOOKUP in Google Sheets:
- Open your Google Sheet or create a new one.
- Prepare your data with the lookup range, lookup value, and desired output column.
Here's an example of a simple dataset:
ID | Name |
---|---|
1 | Alice |
2 | Bob |
3 | Carol |
Now, let's say we want to find the name associated with ID "4". Since "4" is not in the ID column, this will result in an error when using VLOOKUP.
- Click on a cell where you want to display the result of the VLOOKUP function.
- Use the IFERROR function in combination with VLOOKUP as follows:
=IFERROR(VLOOKUP(lookup_value, range, index, [is_sorted]), error_value)
lookup_value
: The value you want to look up.range
: The range of cells where the lookup should be performed.index
: The column index of the value you want to return.[is_sorted]
: Optional. FALSE for an exact match, or TRUE for an approximate match. If omitted, the default is TRUE.error_value
: The value to return if an error occurs.
In our example, we want to look up the name associated with ID "4" using the dataset in cells A1:B4. We'll set the error value to "Not found". The formula will look like this:
=IFERROR(VLOOKUP(4, A1:B4, 2, FALSE), "Not found")
- Press Enter to see the result. In our example, the result will be "Not found" since ID "4" is not in the dataset.
Example
Here's an example using the dataset and formula mentioned earlier:
ID | Name | Lookup | Result |
---|---|---|---|
1 | Alice | 4 | Not found |
2 | Bob | ||
3 | Carol |
In this example, we have used the IFERROR function with VLOOKUP to look up the name associated with ID "4" in cells A1:B4. Since ID "4" is not in the dataset, the result displayed in the "Result" column is "Not found", which is the custom error value we specified in the formula.