where data (B5:E15) and n (G5) are named ranges. This formula returns TRUE if a row is a “last n row”, and FALSE if not. In brief, we get the current row in the workbook, then subtract the first row number of the range plus 1. The result is an adjusted row number that begins at 1. The INDEX function is simply one way get the first cell in a given range: This is for convenience only. The formula could be re-written like as: Once we have a current row number, we can compare the row number to the total rows in the data less n: If this expression returns TRUE, the current row is one of the last n rows we are looking for.

Last n rows in a table

If data is in an Excel table, the formula can be adapted like this:

The logic is exactly the same, but we use a slightly different approach to get the first cell in the table: You can think of the @ character as indicating “single”: As before, the table formula returns TRUE in “last n rows” and FALSE in others.

Last row only

To test for the last row only, you can use a slightly simplified version of the formula:

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.