Summary

To get the last relative position (i.e. last row, last column) for mixed data that contains no empty cells, you can use the COUNTA function.

In the example shown, the formula in D5 is:

=COUNTA(B4:B100)

Last *relative* position

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. It's important to understand that we are after the last *relative position* inside a given range not the row number on the worksheet:

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

Generic formula

=COUNTA(range)

Explanation 

This formula uses the COUNTA function to count values in a range. COUNTA counts both numbers and text to so works well with mixed data.

The range B4:B8 contains 5 values, so COUNTA returns 5. The number 5 corresponds to the last row (last relative position) of data in the range B4:B100.

Note: This approach will fail if the range contains blank/empty cells. This formula based on the LOOKUP function can handle empty cells in the data.

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.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.