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 or Asterisks from a Lookup.

Returning Blanks or Asterisks from a Lookup

Written by Allen Wyatt (last updated October 10, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


4

Bob asked if there was a way to use VLOOKUP to return blanks or asterisks if the function cannot make a match in a lookup table.

Yes, this can be done, but not without making your formula just a bit more complex. The trick is to remember that VLOOKUP can operate in one of two ways. By default, it returns the next lower value to the one being looked for, if the data table is in ascending order and if there isn't an exact match. However, you can force VLOOKUP to only return exact matches, if desired. Consider the following example:

=VLOOKUP(5,A1:B10,2,FALSE)

This example searches through the lookup table (A1:B10) looking for the value 5 in the first column of the table. If it is found, then the corresponding value from the second column is returned. If it is not found, then VLOOKUP returns an #N/A error, indicating it could not locate the value. (The FALSE value as the fourth parameter indicates you don't want approximate matches.)

The key, then, is to play off this #N/A value and build what you want returned if there isn't a match. The following formula will return a series of five asterisks if there wasn't a match in the lookup:

=IF(ISNA(VLOOKUP(5,A1:B10,2,FALSE)),"*****",VLOOKUP(5,A1:B10,2,FALSE))

The ISNA function is used to test if the result of VLOOKUP is the #N/A error. If it is, then the asterisks are returned; if not, then the lookup value is returned. If you want the formula to return "nothing," then you can use this variation:

=IF(ISNA(VLOOKUP(5,A1:B10,2,FALSE)),"",VLOOKUP(5,A1:B10,2,FALSE))

This version returns a blank string if there was not a match in the lookup table. For some uses, this may not be exactly what you want. You may find it more appropriate to return a zero, and then hide zeroes in the worksheet (File | Options | Advanced | Display Options for this Worksheet | Clear the Show a Zero in Cells that have Zero Value). If you'd like a zero returned, then it takes only one change:

=IF(ISNA(VLOOKUP(5,A1:B10,2,FALSE)),0,VLOOKUP(5,A1:B10,2,FALSE))

Of course, you could also use the IFERROR function to find what you need. The following variation on the formula will work just fine:

IFERROR(VLOOKUP(5,A1:B10,2,FALSE),"*****")

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10940) 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 or Asterisks from a Lookup.

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

Printing a Single Column in Multiple Columns

Ever printed out a worksheet only to find that you have text only at the left side of each page? You can use more of each ...

Discover More

Problems with Custom Views

If you get an error when you try to use one of your custom views, it could be due to the protection you have applied to ...

Discover More

Using Macros in Protected Workbooks

Having problems with using macros in a protected workbook? There could be any number of causes (and solutions) as ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Converting to Octal

If you need to do some work in the base-8 numbering system (octal), you'll love two worksheet functions provided by Excel ...

Discover More

Using the CONCATENATE Worksheet Function

The process of combining string (text) values to make a new string is called concatenation. Excel provides the ...

Discover More

Returning Blanks with VLOOKUP

Normally the VLOOKUP function returns a value, and if it can't return a value it returns a zero. Here's how you can use ...

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 six minus 4?

2020-10-14 04:31:55

Alex B

@David, appreciate the feedback. I am only on the standard Office 365 so you should have access to all the new Dynamic Array functions. The FILTER function seems to be particularly versatile. I have seen some very unexpected uses of that one.


2020-10-13 09:50:52

David Gray

Thanks for the heads up, Alex. Since my copy of Excel is part of Office 365, I have access to XLOOOKUP, but I was unaware of its existence.


2020-10-11 10:47:04

David Gray

Another useful option addresses the issue of blank lookup values without the need for hiding all zeros, which prevents differentiating blank cells from cells with a value of zero. This is especially significant when you take into account that when the target of a lookup is set to blank by a formula, the lookup functions return a zero.

=if(LEN(VLOOKUP(5,A1:B10,2,FALSE))>0,VLOOKUP(5,A1:B10,2,FALSE),"")

This formula leverages the fact that the length of a cell that has a computed value of blank is zero, the length of the empty string. If said length is greater than zero, the TRUE argument of the IF function returns the lookup value. Otherwise, its FALSE argument returns the empty string.


2020-10-10 06:28:01

Alex B

If you have Office 365 you could go straight to XLOOKUP
Format:-
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
eg
=XLOOKUP(5,A1:A10,B1:B10,"*****")
Where the "if_not_found" is "*****" and could just as easily be "" or 0.


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.