You can very easily skip blank cells in Vlookup in Google Sheets. You can either use the FILTER function or the QUERY function together with Vlookup in Google Sheets.
It may not be as much simpler in Excel since the lack of these two functions. Now about how to skip blank cells in Vlookup.
Vlookup searches down the first column in a table for your given search key. If found, the formula would return value from any cell in that found row. This you may already know.
The returned cell value can be any values (text, numeric or date) or may sometimes blank. If the cell is blank, Vlookup doesn’t skip the row. Instead, it would return blank. But you can skip blank rows in Vlookup.
Then how to skip blank cells in Vlookup in Google Sheets?
In the above example, my lookup search key is “B”. I want a Vlookup formula that would search down Column A for the value “B” and return value from the same row in column B. If you use Vlookup in this case, it would return blank.
=vlookup(D1,A1:B7,2,FALSE)
As you can see, Vlookup will find the search key “B” in cell A2. What we want is the result of column B in that row. That means the value in cell B2.
Here, cell B2 doesn’t contain any value and it’s blank. So Vlookup will only return blank. I want to skip this row and search for the second appearance of “B” in column A, i.e. in cell A5 and return the value from B5 since it’s not blank. How?
How to Skip Blank Cells in Vlookup in Google Sheets
You can tweak Google Sheets Vlookup function in many ways. Skipping blank cells are also possible.
You can use Vlookup to return an Array result, for Image Lookup, to Return Multiple Columns, Case Sensitive Vlookup etc.
If you are interested to learn advanced Vlookup formulas, I suggest you search this page using the search term “Vlookup” in the search field that you can find on the top of this page.
The Formula to Skip Blank Cells in Vlookup
The below Vlookup formula is based on the above Sample data and cell references. This Vlookup formula can skip blank cells.
=VLOOKUP(D1,query(A1:B7,"Select * where B is not null"),2,FALSE)
Before taking you to the formula explanation, first, we can see the Vlookup Syntax.
VLOOKUP(search_key, range, index, [is_sorted])
If you analyze the formula, you can understand that in my formula that to skip blank cells in Google Sheets, the “range” is not a direct table/array reference. Instead, it’s replaced by a Query formula. This Query is the soul of my formula. What does it do?
The Query part in the above formula, filtered out rows that contain no values (blank) in column B. Here is that Query formula result for your reference.
This’s our actual Vlookup range and the Vlookup formula searches down column 1 in this table to find the search key “B” and properly return the value from Column B.
This time since there are no blank cells, there is no issue with the blank cell as output. That’s all. This way you can skip blank cells in Vlookup in Google Sheets. Enjoy!
Thank you very much. Helped me a lot.
Hi Prashanth,
Thanks for the article! What do I do when my search key is not “B” but a random string which also constantly changes when I copy the formula to other cells? How would I have to tweak the “Select * where B is not null” part? Thanks!
Hi, Dom,
The Vlookup range as per my example is A1:B7.
We want Vlookup to return value from column B. So using Query we simply filter out blanks in the second column.
So obviously “B” is not the criterion. It’s the column ID of the second column.
If your range is Q1:W10, then the reference for the second column will be “R”, not “B”.
To dynamic column ID, please refer these two articles.
1. Match Function in Query Where Clause in Google Sheets.
2. How to Get Dynamic Column Reference in Google Sheets Query.
Thanks for the interesting post. Is it possible that if VLOOKUP one column blank then it automatically selects the next column? If yes, please let me know.
Thanks
Hi, Suparno Mitra,
I have a similar Vlookup tutorial in the past. See if that helps?
Move Index Column If Blank in Vlookup in Google Sheets
Best