# How to get last match that cell contains one of several values in a range

This post explains that how to check a cell that contains one of several values in another range, and then return the last match value.  And we talked that how to test a cell to see that if it contains one of several values in a list in the previous post. And this post will guide you how to get the last match value in the range.

## Get Last Match that cell contains one of several values

If you want to check a cell that if it contains one of several values in a range, you can use the SEARCH function to search find_text in a range inside a text string. Then we can use the LOOKUP function to get the last match values.

For example, you have a list of text strings in the range B1:B4 and you need to check each cell if it contains one of several values in the range D2:D4, if TRUE, then return the last match values from the range D2:D4. You can write down the following formula:

`=LOOKUP(2,1/SEARCH(\$D\$2:\$D\$4,B1), \$D\$2:\$D\$4)`

Let’s see how this formula works:

= SEARCH(\$D\$2:\$D\$4,B1)

This  formula will search each value from the range D2:D4 inside within_text in Cell B1, if it find the matched string, then return the position of the first character in Cell B1, if not, it returns the #VALUE error.  So this formula will return an array result like this:

`{1;7;12}`

=1/SEARCH(\$D\$2:\$D\$4,B1)

The array result returned by the SEARCH function is divided by number 1, then this formula returns another new array result that is composed of the #VALUE! Error and decimal values. If the item is a decimal value, then it indicates that one value found. The array is like this:

`{1;0.142857142857143;0.0833333333333333}`

The returned array result goes into the LOOKUP function as its lookup_vector argument.

=LOOKUP(2,1/SEARCH(\$D\$2:\$D\$4,B1), \$D\$2:\$D\$4) You can see that the value of lookup vector will never larger than 1, and the lookup value is set to 2. So the lookup value is not able to be found. So the LOOKUP function will match the last numeric value in the array result of the lookup_vector, then return the value from the same position in the range D2:D4.

### Related Formulas

• Check If Cell Contains All Values from Range
If you want to check if a cell contains all values in a list, you can use a combination of the SEARCH function, the SUMPRODUCT function, the ISNUMBER function and COUNTA function…
• Get first match that cell contains one of several values in a range
You can use a combination of the INDEX function, the MATCH function, the ISNUMBER function and the SEARCH function to create a new excel array formula to get first match cell contains…
• Check if Cell contains one of many values from range
Assuming that you have a list of text strings in the range B1:B3 and you want to check each text string if it contains one of several values in a range E1:E3. If it contains any of text string in range E1:E3, then it should be return TRUE value, otherwise, it should return FALSE….

### Related Functions

• Excel LOOKUP function
The Excel LOOKUP function will search a value in a vector or array.The syntax of the LOOKUP function is as below:= LOOKUP (lookup_value, lookup_vector, [result_vector])…
• Excel SEARCH function
The Excel SEARCH function returns the number of the starting location of a substring in a text string.The syntax of the SEARCH function is as below:= SEARCH  (find_text, within_text,[start_num])…

Related Posts
If Cell Contains Certain Text OR Equals Certain Text

IF cell equals certain text IF function is frequently used in Excel worksheet to return “true value” or “false value” based on the logical test result. If you want to test values to see if they equal certain text like ...

How to Extract Text between Two Text Strings in Excel

This post will guide you how to extract text between two given text strings in Excel. How do I get text string between two words with a formula in Excel. Extract Text between Two Text Strings Assuming that you have ...

How to Return a Value If a Cell Contains a Specific Text in Excel

This post will guide you how to return a value if a cell contains a certain number or text string in Excel. How do I check if a Cell contains specific text and then return another specific text in another ...

Insert The File Path and Filename into Cell

This post will guide you how to insert the file path and filename into a cell in Excel. Or how to add a file path only in a specified cell with a formula in Excel. Or how to add the ...

Sort Cells by Specific word or words

This post will guide you how to sort cells or text values in a column based on a specific word even if the word is in the text string in the cell. How do I sort cells in a column ...

Highlight Rows

This post will teach you how to highlight rows in a table with conditional formatting in Excel. You will learn that how to change the color of the entire rows if the value of cells in a specified column meets ...

How to replace all characters after the first specific character

This post will guide you how to replace all characters after the first match of a specific character with a new text string in excel. How to replace all substrings after the first occurrence of the comma character with another ...

How to extract text after the second or nth specific character (space or comma)

In the previous post, we talked that how to extract text after the first occurrence of the comma character in excel. And this post explains that how to get a substring after the second or nth occurrence of the comma ...

How to extract text before the second or nth specific character (space or comma)

Before we talked that how to extract text before the first space or comma character in excel. And this post will guide you how to extract a substring before the second or nth specific character, such as: space or comma ...

How to extract text after first comma or space

In the previous post, we talked that how to extract substring before the first comma or space or others specific characters in excel. And this post will guide you how to extract text after the first comma or space character ...

Sidebar