Skip to content
Free Excel Tutorials
  • Home
  • Excel For Beginners
  • Excel Intermediate
  • Advanced Excel For Experts

Data Analysis

  • How to create Checklist in Excel
  • How to Create One and Two Variable Data Tables in Excel
  • Get column index in Excel Table
  • Subtotal function in Excel
  • How to create Gauge Chart in Excel

References

  • Create hyperlink with VLOOKUP in Excel
  • How to get relative column numbers in a range in Excel
  • MATCH function: Description, Usage, Syntax, Examples and Explanation
  • Count rows that contain specific values in Excel
  • Extract all partial matches in Excel

Data Validations

  • Excel Data validation must not contain
  • Excel Data validation must begin with
  • Excel Data validation don’t exceed total
  • Excel Data validation with conditional list
  • Excel Data validation unique values only

Get last match cell contains in Excel

by

This tutorial shows how to Get last match cell contains in Excel using the example below;

Formula

=LOOKUP(2,1/SEARCH(things,A1),things)

Explanation

To check a cell for one of several things, and return the last match found in the list, you can use a formula based on the LOOKUP and SEARCH functions. In the case of multiple matches found, the formula will return the last match from the list of “things”.
In the example shown, the formula in C5 is:

=LOOKUP(2,1/SEARCH(things,B5),things)

How this formula works

Context: you have a list of things in the named range “things” (E5:E8), and you want to check cells in column B to see if they contain these things. If so, you want to return the last item from”things” that was found.

Worked Example:   Highlight cells that contain in Excel

In this formula, the SEARCH function is used to search cells in column B like this:

SEARCH(things,B5)

When SEARCH finds a match, it returns the position of the match in the cell being searched. When search can’t find a match, it returns the #VALUE error. Because we are giving SEARH more than one thing to look for, it will return more than one result. In the example shown, SEARCH returns an array of results like this:

{8;24;#VALUE!;#VALUE!}

This array is then used as a divisor for the number 1. The result is an array composed of errors and decimal values. The errors represent things not found, and the decimal values represent things found. In the example shown, the array looks like this:

{0.125;0.0416666666666667;#VALUE!;#VALUE!}

This array serves as the “lookup_vector” for the LOOKUP function. The lookup value is supplied as the number 2, and the result vector is the named range “things”. This is the clever part.

Worked Example:   Lookup latest price in Excel

The formula is constructed in such a way so that the lookup vector will never contain a value larger than 1, while the the lookup value is 2. This means the lookup value will never be found. In this case, LOOKUP will match the last numeric value found in the array, which corresponds to the last “thing” found by SEARCH.

Worked Example:   Count cells that do not contain many strings in Excel

Finally, using the named range “things” supplied as the result vector, LOOKUP returns the last thing found.

With hard-coded values

Using a range like “things” makes it easy to modify the list of search terms (and add more search terms), but it’s not a requirement. You can also hard-code values directly into the formula like this:

=LOOKUP(2,1/SEARCH({"red","blue","green"},B5),{"red","blue","green"})

Post navigation

Previous Post:

Weighted average in Excel

Next Post:

Win loss points calculation in Excel

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Learn Basic Excel

Ribbon
Workbook
Worksheets
Format Cells
Find & Select
Sort & Filter
Templates
Print
Share
Protect
Keyboard Shortcuts

Categories

  • Charts
  • Data Analysis
  • Data Validation
  • Excel Functions
    • Cube Functions
    • Database Functions
    • Date and Time Functions
    • Engineering Functions
    • Financial Functions
    • Information Functions
    • Logical Functions
    • Lookup and Reference Functions
    • Math and Trig Functions
    • Statistical Functions
    • Text Functions
    • Web Functions
  • Excel VBA
  • Excel Video Tutorials
  • Formatting
  • Grouping
  • Others

Logical Functions

  • IFNA function: Description, Usage, Syntax, Examples and Explanation
  • Complete List of Excel Logical Functions, References and Examples
  • How to use Excel AND Function
  • How to use Excel XOR Function
  • How to return blank in place of #DIV/0! error in Excel

Date Time

  • Calculate time difference in hours as decimal value in Excel
  • How to enter Today’s Date or Static Date and Time in Excel
  • How to calculate working days left in month in Excel
  • Pad week numbers with zeros in Excel
  • Convert text timestamp into time in Excel

Grouping

  • How to randomly assign data to groups in Excel
  • Group times into unequal buckets in Excel
  • Categorize text with keywords in Excel
  • Group arbitrary text values in Excel
  • Group numbers at uneven intervals in Excel

General

  • Basic error trapping example in Excel
  • How to calculate percentage of total in Excel
  • How to Delete Cells, Row and Rows in Excel
  • How to calculate percent change in Excel
  • How to count total number of cells in a rectangular range in Excel
© 2023 xlsoffice . All Right Reserved. | Teal Smiles | Abbreviations And Their Meaning