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 21, 2024)
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

Too Many Temporary Files

Word, as it operates, creates lots of temporary files on your system. Here are some ideas for dealing with that plethora ...

Discover More

Deleting Graphics when Deleting a Row

If you use Excel to keep a graphic with each row of data you amass, you may wonder if there is a way to easily delete the ...

Discover More

What is a Desktop.ini File?

When browsing through your system, you might see several files named Desktop.ini. This tip explains what these files are ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Displaying Letter Grades

Grading in schools is often done using numeric values. However, you may want to change those numeric values into letter ...

Discover More

Returning the Left-most Characters

When working with text in a formula, you may need to extract the left-most characters from a string of text or from a ...

Discover More

Converting Radians to Degrees

When applying trigonometry to the values in a worksheet, you may need to convert radians to degrees. This is done by ...

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 two more than 7?

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.