Google Sheets: Get the Last Row with Any Data Across Multiple Columns

It’s common to have several empty rows at the bottom of a Google Sheet, especially when you’re reserving space for future data entry. In such cases, how do you get the last row with any data in Google Sheets, particularly when working across multiple columns?

If you’re working with a single column, the task is fairly simple using LOOKUP-based functions.

Get the Last Row in a Single Column

For example, to get the last row in column A, you can use:

=ARRAYFORMULA(XLOOKUP("?*", A:A & "", A:A, , 2, -1))

However, this approach doesn’t work when you want to get the last row with any data in Google Sheets across multiple columns—since the last row could have data in just one column, several columns, or all of them.

To solve this, here are two robust methods that work across a 2D range: one using the LAMBDA helper function and another using LOOKUP and SORT logic.

Sample Data

Consider the data in range A1:C:

Sample data to get the last row with any data in Google Sheets across multiple columns

In this case, row 7 is the last row that contains any data—Fiona’s name appears in column B.

Now, how can you retrieve that row from the full range A1:C, without hardcoding A1:C7?

Method 1: Get the Last Row with Any Data – LAMBDA Approach

=CHOOSEROWS(
   A1:C, 
   MAX(
      BYROW(A1:C, LAMBDA(val, IF(COUNTA(val), ROW(val))))
   )
)

This formula dynamically returns the last row with any data in a 2D range.

How it works:

  • BYROW() scans each row and processes it individually.
  • COUNTA(val) counts non-empty cells.
  • IF(..., ROW(val)) returns the row number for rows with any data.
  • MAX() gets the highest row number with data.
  • CHOOSEROWS() returns that row from the original range.

Simple and elegant!

To learn more about BYROW, check out: How to Use the BYROW Function in Google Sheets.

Method 2: Get the Last Row with Any Data – Sort & Lookup Approach

While the LAMBDA approach is compact, it might not perform well on very large datasets. In such cases, use this alternative:

=ARRAYFORMULA(
  LET(
    range, TRANSPOSE(A1:C),
    bt, NOT(ISBLANK(range)),
    errv, IF(bt, bt, NA()),
    rseq, SEQUENCE(COLUMNS(errv), 1, -1, -1),
    swap, CHOOSECOLS(errv, rseq),
    row_, SORTN(swap),
    id, -XMATCH(TRUE, row_),
    CHOOSEROWS(A1:C, id)
  )
)

Understanding the Logic

Let’s break down the formula step-by-step using a smaller example like A1:C10:

1. TRANSPOSE(A1:C10)
Rotates the data so rows become columns.

DepartmentHRITFinanceSales
NameAliceBobCharlieDianaEthanFiona
Score82917889

2. NOT(ISBLANK(range))
Produces a Boolean array where TRUE marks a cell with data and FALSE marks an empty cell.

TRUETRUETRUETRUEFALSETRUEFALSEFALSEFALSEFALSE
TRUETRUETRUETRUETRUETRUETRUEFALSEFALSEFALSE
TRUETRUETRUEFALSETRUETRUEFALSEFALSEFALSEFALSE

3. IF(bt, bt, NA())
Replaces all FALSE values (i.e., blank cells) with #N/A. This helps prevent empty rows from being considered in the next steps.

TRUETRUETRUETRUE#N/ATRUE#N/A#N/A#N/A#N/A
TRUETRUETRUETRUETRUETRUETRUE#N/A#N/A#N/A
TRUETRUETRUE#N/ATRUETRUE#N/A#N/A#N/A#N/A

4. SEQUENCE(...) + CHOOSECOLS(...)
Reverses the column order, effectively flipping the data from right to left. This positions the bottom-most rows of the original range toward the beginning of the array.

#N/A#N/A#N/A#N/ATRUE#N/ATRUETRUETRUETRUE
#N/A#N/A#N/ATRUETRUETRUETRUETRUETRUETRUE
#N/A#N/A#N/A#N/ATRUETRUE#N/ATRUETRUETRUE

5. SORTN(...)
Returns the first row (from the flipped data) that contains at least one TRUE value. This corresponds to the last row with any data in the original orientation.

#N/A#N/A#N/ATRUETRUETRUETRUETRUETRUETRUE

6. XMATCH(TRUE, row_)
Identifies the position of the first TRUE in that sorted row. Since the data was reversed, this value tells us how far from the bottom the last row with data is. We negate the result using -XMATCH(...) so it can be used with CHOOSEROWS to return the row from the bottom.

-4

7. CHOOSEROWS(A1:C, id)
Uses the negative index to retrieve the correct row from the bottom of the original range.

This technique is particularly helpful for large or irregular datasets where the LAMBDA approach may slow down. It demonstrates a clever use of transposing, logical masking, and reverse indexing to get the last row with any data in Google Sheets.

Conclusion

You now have two powerful methods to get the last row with any data across multiple columns in Google Sheets:

  1. LAMBDA + BYROW – best for smaller, more manageable datasets.
  2. Sort + Lookup Logic – better for larger sheets with potential LAMBDA limitations.

Both approaches allow you to dynamically reference only the relevant portion of your dataset without manually trimming the range.

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.

How to Calculate Digital Root in Google Sheets

The digital root is the single-digit value you get by repeatedly summing the digits...

How to Build an Advanced Book Tracker in Google Sheets: Formulas Explained

If you're tired of forgetting what you've read, which books you rated 5 stars,...

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...

More like this

How to Calculate Digital Root in Google Sheets

The digital root is the single-digit value you get by repeatedly summing the digits...

How to Build an Advanced Book Tracker in Google Sheets: Formulas Explained

If you're tired of forgetting what you've read, which books you rated 5 stars,...

Google Sheets Reading List Tracker Template (Free Download)

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

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.