VLOOKUP to Get Last Non-blank Value in the Found Row in Sheets

Published on

In this tutorial, you’ll learn how to use VLOOKUP to get the last non-blank value or item in the found row in Google Sheets.

How Is This Different from a Regular VLOOKUP Formula in Sheets?

Normally, when using VLOOKUP in Sheets, we specify a column in the lookup range to return the result. In VLOOKUP’s terms, this is called the index (the relative position of the output column).

For example, we can use the following VLOOKUP formula in Google Sheets to search the range A2:E for the name “Maria” in column A and return a value from the second column of the found row:

=VLOOKUP("Maria", A2:E, 2, FALSE)

In this example, the index number (the column position for the result) is 2, so we will get the value from cell B4.

Understanding the Last Non-empty Value in a Range in Google Sheets
image_1

Syntax: VLOOKUP(search_key, range, index, [is_sorted])

VLOOKUP Formula to Get the Last Non-blank Value in the Found Row

Here’s a generic formula to find the last non-blank value in the found row:

=CHOOSECOLS(TOROW(ARRAYFORMULA(VLOOKUP(search_key, range, SEQUENCE(1, COLUMNS(range)), FALSE)), 3), -1)

Where:

  • search_key is the value you’re looking up.
  • range is the lookup range where VLOOKUP searches for the search_key in the first column.

This formula will return the result from the last non-blank column in the row.

Example

Let’s say the sample data is in the range A2:E. To search for “Maria” in column A and return the value from the last non-blank cell in the found row, use the following formula:

=CHOOSECOLS(TOROW(ARRAYFORMULA(VLOOKUP(G2, $A$2:$E, SEQUENCE(1, COLUMNS($A$2:$E)), FALSE)), 3), -1)
VLOOKUP to Get the Last Non-blank Value in the Found Row – Example in Google Sheets

How Does This Formula Work?

  • ARRAYFORMULA(VLOOKUP(G2, $A$2:$E, SEQUENCE(1, COLUMNS($A$2:$E)), FALSE)): The VLOOKUP searches for “Maria” in the range A2:E and returns the entire row.
  • TOROW(..., 3): This removes empty cells from the returned row.
  • CHOOSECOLS(..., -1): This returns the last non-blank value from the row.

This is how the VLOOKUP formula works to search for a value in a range and return the last non-blank value in the found row.

VLOOKUP to Get the Last Non-blank Value in Each Row in Google Sheets

You can use the above VLOOKUP formula to find the last non-blank value in each row.

In cell F2, enter the following formula and drag it down:

=CHOOSECOLS(TOROW(ARRAYFORMULA(VLOOKUP(A2, $A$2:$E, SEQUENCE(1, COLUMNS($A$2:$E)), FALSE)), 3), -1)

The difference here is that we’ve specified the first column letter (A2) as the search key.

VLOOKUP to Get the Last Non-blank Value in Each Row in Google Sheets

Auto-expanding the Formula Using MAP

If you want to auto-expand the formula for an entire column, you can use the MAP function as follows:

=IFERROR(MAP(A2:A, LAMBDA(val, CHOOSECOLS(TOROW(ARRAYFORMULA(VLOOKUP(val, A2:E, SEQUENCE(1, COLUMNS(A2:E)), FALSE)), 3), -1))))

The IFERROR function ensures that errors from blank rows are removed.

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.

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

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

More like this

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

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

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.