How to Extract the Last N Non-Blank Rows in Excel Dynamically

You can use the following formula to extract the last N non-blank rows in Excel:

=TAKE(FILTER(range, BYROW(range, LAMBDA(row, COUNTA(row)>0))), -N)

where:

  • range – The range to filter.
  • N – The number of last non-blank rows you want to extract.

Introduction

Extracting the last N non-blank rows from a dataset is especially useful when dealing with dynamic data where blank rows may appear in between. Additionally, if you reference a large range to accommodate future entries, there will definitely be blank rows at the end.

Extracting the last N non-blank rows has several benefits, such as:

  • Analyzing the most recent entries while ignoring blanks.
  • Creating a dynamic report that updates as new data is added.
  • Extracting the latest transactions, sales, or stock updates from a dataset.

Example

Assume your data is in the range A1:C1000, but actual data is present only up to row 31 (A1:C31), with some blank rows in between. If you want to extract the last 10 non-blank rows, you can use the following formula:

=TAKE(FILTER(A1:C1000, BYROW(A1:C1000, LAMBDA(row, COUNTA(row)>0))), -10)
Extract the last N non-blank rows in Excel dynamically

How This Formula Works

  • BYROW(A1:C1000, LAMBDA(row, COUNTA(row)>0)): Checks each row to see if it has at least one non-blank cell.
    • The COUNTA function counts the values in the current row.
    • >0 ensures that the function returns TRUE for non-blank rows and FALSE for blank rows.
    • BYROW applies this check to each row in the range.
  • FILTER(A1:C1000, … ) : Keeps only the non-blank rows from the dataset.
    • It filters the rows where BYROW returns TRUE.
  • TAKE( … , -10 ): Extracts the last 10 rows from the filtered dataset.

Additional Tip: Extract N Rows from the Last Non-Blank Row to the Top

If you just want to remove empty rows from the bottom and extract 10 rows from the last non-blank row, you can use a combination of TRIMRANGE and TAKE as follows:

=TAKE(TRIMRANGE(A1:C1000), -10)
  • The TRIMRANGE function removes empty rows from the bottom.
  • The TAKE function extracts the last 10 rows from this trimmed range.

This formula is more resource-friendly as it doesn’t use the BYROW Lambda function.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Google Sheets Reading List Tracker Template (Free Download)

Looking for a smarter, more visual way to manage your reading goals? This Google...

Custom Order for QUERY Pivot Headers in Google Sheets

By default, when you use the PIVOT clause in a Google Sheets QUERY, the...

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

More like this

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

Sort Each Row Individually in Excel Using a LAMBDA Formula

Sorting rows in Excel typically refers to rearranging entire datasets based on values in...

Sort by Field Labels Using the SORT and XMATCH Combo in Excel

Want to sort your Excel data by column names instead of column positions? Learn...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.