Excel Formula to Find the Last Matching Cell Above a Row
Question details
The user needs a formula to search upward in a column for a specific string (like an email domain) and return the value from the cell exactly one row above the last matched criteria.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Locating the last instance of a specific text string within a dataset and extracting data positioned relative to that match, specifically offset by minus one row.
- Observed behavior
- The user successfully retrieves the target cell value by using advanced lookup formulas with strategically offset ranges or bottom-to-top search parameters.
Ensure your dataset does not contain merged cells, as this can disrupt the row indexing and cause array formulas to return incorrect offsets.
Use the LOOKUP and SEARCH Function Combination
This method works in all versions of Excel to search for a text string and return the value directly above the last matching occurrence.
By intentionally offsetting the search range and the return range by one row, the LOOKUP function naturally retrieves the cell situated exactly one row above the matched criteria.
Click on the empty cell where you want the final extracted value to be displayed.
Type the formula =LOOKUP(2,1/SEARCH("example.cz",A2:A10),A1:A9) into the formula bar. Replace "example.cz" with the actual text or email domain you are trying to find.
Verify that your search range (A2:A10) starts and ends exactly one row below your return range (A1:A9). Press Enter to apply the calculation.

Use XMATCH and INDEX (Microsoft 365 & Office 2021)
A modern and highly robust approach for newer spreadsheet versions that natively support searching from bottom to top.
Easily Handle Complex Array Formulas in WPS Spreadsheet
WPS Spreadsheet provides flawless support for advanced data lookup functions like LOOKUP, INDEX, and XMATCH. You can process heavy array calculations and align offset ranges perfectly without any performance lag.
- 1. Open your data file: Launch WPS Spreadsheet and open your existing .xlsx or .csv data file.
- 2. Select the target cell: Click on the blank cell where you want to execute your bottom-up lookup.
- 3. Apply the formula: Type your LOOKUP or INDEX formula into the formula bar, ensuring your search and return ranges are properly offset.
- 4. Execute the calculation: Press Enter to instantly fetch the corresponding cell value from the row above your matched criteria.

Frequently Asked Questions
Why does my LOOKUP formula return an #N/A error?
This error occurs if the target string cannot be found anywhere in the specified search range. Verify your spelling, check for hidden trailing spaces in the dataset, and ensure you are using wildcards correctly if needed.
Can I reference a range on a different worksheet with this formula?
Yes, you can pull data from another sheet by appending the sheet name followed by an exclamation mark before the cell range, such as =LOOKUP(2,1/SEARCH("text",Sheet2!A2:A10),Sheet2!A1:A9).
Why does the XMATCH formula display a #NAME? error?
The XMATCH function was introduced in Microsoft 365, Office 2021, and recent versions of WPS Office. If you are using an older spreadsheet version, the program will not recognize XMATCH. In that case, use the LOOKUP method instead.
What happens if I don't offset the ranges in the LOOKUP formula?
If both the search range and the return range are identical (e.g., both A1:A10), the formula will return the value from the exact same row where the match is found, rather than the row above it.




