How to Reference the Last Nonblank Cell in an Excel Formula Range
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.

- 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.
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.
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.
Click on the cell where you want to output your dynamic array or calculated result.
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,"")
Press the Enter key. The range will dynamically adjust from cell M1 down to the absolute last non-blank row in column M.

Use COUNTA and INDEX for Contiguous Data
If your data is strictly contiguous with no gaps and begins exactly in row 1, you can use a simpler COUNTA formula to determine the end of the range.
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. Open your dataset: Launch WPS Spreadsheet and open the document containing your column data.
- 2. Input the dynamic formula: Select an empty cell and type your INDEX and LOOKUP formula to define the dynamic range.
- 3. Calculate and evaluate: Press Enter to instantly process the data. The range will auto-adjust based on your latest inputs.
- 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.

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.




