How to Find the Last Nonblank Cell and Return Its Row in Excel
Question details
The user needs an Excel formula to locate the last non-empty cell within a specific range and return its exact row number.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Retrieving the latest time-series data or identifying the most recent entry in a continuously updated dataset.
- Observed behavior
- The goal is to extract the correct row index of the final data point without triggering #SPILL or #N/A errors when utilizing array functions.
Identify the exact data column or range (such as B2:B7) where you want to find the last entry, and make sure seemingly blank cells do not contain hidden space characters.
Use the LOOKUP Formula to Return the Row Number
The LOOKUP formula is a highly reliable method for finding the last non-empty cell in a column and returning its corresponding row number.
By dividing 1 by a Boolean array (where the cell is not blank), the formula generates an array of 1s and #DIV/0! errors. The LOOKUP function ignores the errors, matches the last numeric value, and returns the corresponding row index.
Click on the cell where you want the resulting row number to be displayed (for example, B11).
Type the formula `=LOOKUP(2,1/(B2:B7<>""),ROW(B2:B7))` into the formula bar. Be sure to replace `B2:B7` with your actual data range.
Press the Enter key. The cell will now display the absolute row number of the last populated cell within the selected range.

Use the MATCH Formula for Larger Ranges
If you are working with an extensive dataset and solely need the row index, the MATCH formula is a direct and efficient alternative.
Process Dynamic Time-Series Data Effortlessly in WPS Spreadsheet
WPS Spreadsheet fully supports advanced array formulas like LOOKUP, MATCH, and XMATCH. You can easily locate the last nonblank cells and retrieve dynamic data using identical formulas, all within a lightweight and highly compatible workspace.
- 1. Open Your Data File: Launch WPS Spreadsheet and open the workbook containing your time-series data.
- 2. Select a Output Cell: Click on the cell where you want to output the row number of the latest entry.
- 3. Input the Array Formula: Type `=LOOKUP(2,1/(B2:B7<>""),ROW(B2:B7))` into the formula bar.
- 4. Retrieve the Row Number: Press Enter to instantly view the correct row index, seamlessly compatible with Excel's calculation logic.

Frequently Asked Questions
Why does my XMATCH formula return a #SPILL error?
A #SPILL error occurs in XMATCH when a range is incorrectly passed into the match-mode argument, causing the formula to return an array of values that cannot fit in the target cell. Ensure you only provide single valid parameters (like 0, 1, or -1) for the match-mode argument.
How do I get the actual value of the last nonblank cell instead of the row number?
You can easily modify the LOOKUP formula to return the contents of the cell instead of its row number. Replace the ROW function with your data range, like this: `=LOOKUP(2,1/(B2:B7<>""),B2:B7)`.
Will the LOOKUP formula work if my data range contains a mix of text and numbers?
Yes, the logical test `(B2:B7<>"")` checks whether the cell is not empty. It successfully identifies any populated cell regardless of whether it contains text strings, numerical values, or dates.
Why is my MATCH formula returning a relative position instead of the absolute row number?
The MATCH function returns the relative position of an item within the specified array. If your range is `B5:B15` and the last nonblank cell is `B10`, MATCH returns 6 (the 6th cell in the array), whereas `ROW()` would return 10. You can add the starting row offset to MATCH to get the absolute row number.




