Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Returning Blanks with VLOOKUP.

Returning Blanks with VLOOKUP

Written by Allen Wyatt (last updated September 7, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


5

When you use VLOOKUP to return a value from a data table, the function does not differentiate between blanks and zero values in what it returns. If the source value is zero, then VLOOKUP returns 0. Likewise, if the source is blank, then VLOOKUP still returns the value 0. For some purposes, this may not do—you need to know whether the cell being looked up is blank or if it really contains a 0.

There are many different solutions that could be pursued. One solution relies on the fact that even though VLOOKUP returns a 0, it will correctly report the length of the source cell. Thus, if you use the LEN function on what is returned, if the source cell is empty the LEN function returns 0, but if the source contains a 0 then LEN returns 1 (the 0 value is 1 character in length). This means that you could use the following formula in place of a standard VLOOKUP:

=IF(LEN(VLOOKUP(B1,D:E,2,0))=0,"",VLOOKUP(B1,D:E,2,0))

In this case if the length of what VLOOKUP returns is 0, then the formula returns a blank. Only if the length is not 0 is the result of the VLOOKUP returned.

There are other variations on this same concept, each testing a different characteristic of the data being referenced and then making the decision as to whether to actually look up that data. (As you can surmise, the variation you develop for your needs will depend on the "different characteristics of the data being referenced.")

Here's a variation, for example, that directly tests to see if the source is blank:

=IF(VLOOKUP(B1,D:E,2)="","",VLOOKUP(B1,D:E,2))

The formula can also be modified to check the source cell for multiple conditions. For instance, this variation returns a blank if the source is blank or if the source contains an error value (such as #N/A):

=IFERROR(TRIM(VLOOKUP(B1,H:H,1,FALSE)),"")

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12518) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Returning Blanks with VLOOKUP.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Non-Printing Hyperlinks

Karen is having problems getting hyperlinks to print in a document on her home computer. There are only a limited number ...

Discover More

Adding Comments to Protected Worksheets

When you protect a worksheet, Excel stops users from editing or otherwise making changes to the data in the worksheet. If ...

Discover More

Creating Many Index Entries at Once

Word makes it fairly easy to create an index. It is creating the index entries that can be tedious, especially if you ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Returning an ANSI Value

Need to know the character value of the first character in a string? It's easy to do, without using a macro, by using the ...

Discover More

EOMONTH Function is Flakey

Some users have reported problems using the EOMONTH function in later versions of Excel, beginning with Excel 2007. The ...

Discover More

Exact Matches with DSUM

The DSUM function is very handy when you need to calculate a sum based on data that matches criteria you specify. If you ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

2020-12-10 13:23:13

Kat

Ellybee, Does your suggestion make all zeros go away? Such as, if there is a calculation that results in a zero, does that zero also disappear? That would be a downfall.
Thanks!


2019-07-30 08:52:01

Ellybee

But a MUCH simpler way ...

1. Click the File menu and then choose Options at the bottom of the right pane.
2. Choose Advanced in the left pane. ...
3. In the Display Options For This Worksheet section, uncheck the Show A Zero In Cells That Have Zero Value.
4. Click OK.


2018-08-28 11:34:14

Dennis Costello

Relative to Alex's comment, one might wish to interpret a blank as text in one cell and as a 0 in another - and in that situation things become a lot simpler. For instance, imagine a this group of cells A5:E5

A5 B5 C5 D5 E5
Lbl 1 3 4

If you wanted to have a linked copy of these cells somewhere else, and wanted a blank in cell A5 to appear as a blank but a blank in any of the others to show up as a 0, you could use either of these sets of formulae:
=A5 & "" =B5 =C5 =D5 =E5
=IF(ISBLANK(A5), "", A5) =IF(ISTEXT(B5), 0, B5) =IF(ISTEXT(C5), 0, C5) =IF(ISTEXT(D5), 0, D5) =IF(ISTEXT(E5), 0, E5)

Clearly the formulae in the first set are a lot simpler than those in the second set; I'm kicking myself for not realizing this simple approach because I used formulae almost identical to those in the second set - and a huge number of them - for years in a template spreadsheet I created. Alex is correct, though - if you need to care whether the source has a 0 or is blank the longer formulae is the way to go.

Thanks, Micky, for reminding me to "keep it simple, stupid"!


2018-01-22 00:05:39

Alex B

The only issue with both of these
=IFERROR(TRIM(VLOOKUP(B1,H:H,1,FALSE)),"")
=VLOOKUP(B1,D:E,2,0)&""
they both will always return a text result, so all numbers will returned will be text.
(the original issue referenced distinguishing between blank and zero)
So you may still want to use one of the longer versions.


2018-01-20 15:28:01

Michael (Micky) Avidan

@Allen,
Wouldn't: =VLOOKUP(B1,D:E,2,0)&"" provide the same result ?
----------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” Excel MVP – Excel (2009-2018)
ISRAEL


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.