Quick, clean, and to the point

Last row in mixed data with blanks

Excel formula: Last row in mixed data with blanks
Generic formula 

To get the last relative position (i.e. last row, last column) for mixed data that may contain empty cells, you can use the MATCH function as described below.

Note: this is an array formula and must be entered with Control+Shift+Enter.

In the example shown, the formula in E5 is:


Last *relative* position, not row on worksheet

When constructing more advanced formulas, it's often necessary to figure out the last location of data in a list. Depending on the data, this could be the last row with data, the last column with data, or the intersection of both. We want the last *relative position* inside a given range not the row number on the worksheet:

Illustration of last relative position (last row, last column)

How this formula works

This formula uses the MATCH function configured to find the position of the last non-empty cell in a range.

Working from the inside out, the lookup array inside MATCH is constructed like this:


Note: all values in the array are either 1 or the #DIV/0! error.

MATCH is then set to match the value 2 in "approximate match mode", by omitting the 3rd argument is omitted.

Because the lookup value of 2 will never be found, MATCH will always find the last 1 in the lookup array, which corresponds to the last non-empty cell.

This approach will work with any kind of data, including numbers, text, dates, etc. It also works with null text strings that are returned by formulas like this:


Dynamic range

You can use this formula to create a dynamic range with other functions like INDEX and OFFSET. See links below for examples and explanation:

Inspiration for this article came from Mike Girvin's excellent book Control + Shift + Enter, where Mike does a great job explaining the concept of "last relative position".

Dave Bruns

Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.

Excel foundational video course
Excel Pivot Table video training course
Excel formulas and functions video training course
Excel Shortcuts Video Course
Excel Charts video training course
Video training for Excel Tables