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

Dealing with Oily Skin

Does your skin feel greasy to the touch and are you having problems getting just the right look with your facial makeup? ...

Discover More

Floating Footer

Need some specific text to appear just below the end of the text on the last page of your document? You can accomplish ...

Discover More

Handling Leading Zeros in CSV Files

When dealing with files containing comma-separated values, you want to make sure that what gets imported into Excel ...

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)

Calculating Combinations

The COMBIN function is used to determine the number of combinations that can be made from a group of elements. This tip ...

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

Returning Item Codes Instead of Item Names

The data validation capabilities of Excel are really handy when you want to limit what is put into a cell. However, 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 8 + 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.