logo
search
Formula Errors

How to Reference the Last Nonblank Cell in an Excel Formula Range

Natalie TaylorNatalie Taylor Oct 10, 2026 869 views

Question details

The user needs to create a dynamic formula range that extends to the last non-blank cell in a column, even if the starting cell or intermediate cells are blank.

How to Reference the Last Nonblank Cell in an Excel Formula Range
Product
Excel / WPS Spreadsheet
Device & OS
not provided
Scenario
Building dynamic array formulas, such as WRAPROWS, where the data range must automatically adjust to include all data up to the very last populated cell.
Observed behavior
When using simpler referencing methods on data that starts below row 1 or contains gaps, the formula drops the final cells of the dataset.
Before you start

Ensure your spreadsheet software is updated to a version that supports dynamic array functions if you plan to reshape the referenced data using functions like WRAPROWS.

Solution 1Recommended

Use LOOKUP and INDEX to Find the Last Nonblank Cell

This method is the most robust solution. It correctly identifies the last populated cell even if the column contains scattered blank cells or the data starts below row 1.

The LOOKUP function can be used to scan an entire column and locate the row number of the last non-empty cell. By combining this row number with the INDEX function, you can construct a dynamic range that captures your complete dataset perfectly.

1
Select the target cell

Click on the cell where you want to output your dynamic array or calculated result.

2
Enter the LOOKUP and INDEX formula

Type the formula integrating LOOKUP and INDEX. For example, to wrap data in column M into 6 columns, use: =WRAPROWS(M1:INDEX(M:M,LOOKUP(2,1/(M:M<>""),ROW(M:M))),6,"")

3
Execute the formula

Press the Enter key. The range will dynamically adjust from cell M1 down to the absolute last non-blank row in column M.

Use LOOKUP and INDEX to Find the Last Nonblank Cell
How the LOOKUP logic works: The expression 1/(M:M<>"") creates an array of 1s (for non-blank cells) and #DIV/0! errors (for blank cells). LOOKUP(2, ...) searches for the value 2, which isn't found, so it defaults to the position of the last valid number (1), effectively returning the last non-blank row.
Advanced Spreadsheet Management

Easily Manage Dynamic Ranges with WPS Spreadsheet

WPS Spreadsheet fully supports advanced array formulas, including LOOKUP, INDEX, and modern dynamic array handling. You can seamlessly manipulate, reference, and reshape vast amounts of data using familiar syntax.

  1. 1. Open your dataset: Launch WPS Spreadsheet and open the document containing your column data.
  2. 2. Input the dynamic formula: Select an empty cell and type your INDEX and LOOKUP formula to define the dynamic range.
  3. 3. Calculate and evaluate: Press Enter to instantly process the data. The range will auto-adjust based on your latest inputs.
  4. 4. Debug if necessary: Go to the Formulas tab and use the Evaluate Formula tool if you need to trace how the dynamic range is calculating.
Fully compatible with Microsoft Excel formulas and array functions.Smooth execution of complex nested functions like WRAPROWS and LOOKUP.Free, lightweight, and fast performance even when recalculating large datasets.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the COUNTA method fail if there are blank cells in the column?

The COUNTA function strictly counts non-blank cells. If you have 10 rows of data but 2 are blank, COUNTA returns 8. The INDEX function will then point to row 8 instead of row 10, chopping off the bottom of your dataset.

Can I use the OFFSET function to find the last non-blank cell?

Yes, OFFSET combined with COUNTA (e.g., =OFFSET(M1,0,0,COUNTA(M:M),1)) can create dynamic ranges. However, OFFSET is a volatile function that recalculates every time any change is made on the sheet, which can slow down large files. The INDEX and LOOKUP method is non-volatile and much more efficient.

Why is my WRAPROWS function returning a #NAME? error?

WRAPROWS is a newer dynamic array function. If you receive a #NAME? error, it means your current spreadsheet version does not support this function. Upgrading to the latest version of your spreadsheet software will resolve this compatibility issue.