# Excel 2019: Troubleshoot VLOOKUP

August 07, 2019 - by Bill Jelen

VLOOKUP is my favorite function in Excel. If you can use VLOOKUP, you can solve many problems in Excel. But there are things that can trip up a VLOOKUP. This topic talks about a few of them.

But first, the basics of VLOOKUP in plain English.

The data in A:C came from the IT department. You asked for sales by item and date. They gave you item number. You need the item description. Rather than wait for the IT department to rerun the data, you find the table shown in column F:G.

You want VLOOKUP to find the item in A2 while it searches through the first column of the table in $F$3:$G$30. When VLOOKUP finds the match in F7, you want VLOOKUP to return the description found in the second column of the table. Every VLOOKUP that is looking for an exact match has to end in False (or zero, which is equivalent to False). The formula below is set up properly.

Notice that you use `F4` to add four dollar signs to the address for the lookup table. As you copy the formula down column D, you need the address for the lookup table to remain constant. There are two common alternatives: You could specify the entire columns F:G as the lookup table. Or, you could name F3:G30 with a name such as ItemTable. If you use `=VLOOKUP(A2,ItemTable,2,False)`

, the named range acts like an absolute reference.

Any time you do a bunch of VLOOKUPs, you need to sort the column of VLOOKUPs. Sort ZA, and any #N/A errors come to the top. In this case, there is one. Item BG33-9 is missing from the lookup table. Maybe it is a typo. Maybe it is a brand-new item. If it is new, insert a new row anywhere in the middle of your lookup table and add the new item.

It is fairly normal to have a few #N/A errors. But in the figure below, exactly the same formula is returning nothing but #N/A. When this happens, see if you can solve the first VLOOKUP. You are looking up the BG33-8 found in A2. Start cruising down through the first column of the lookup table. As you can see, the matching value clearly is in F10. Why can you see this, but Excel cannot see it?

Go to each cell and press the `F2` key. The figure below shows F10. Note that the insertion cursor appears right after the 8.

The following figure shows cell A2 in Edit mode. The insertion cursor is a couple of spaces away from the 8. This is a sign that at some point, this data was stored in an old COBOL data set. Back in COBOL, if the Item field was defined as 10 characters and you typed only 6 characters, COBOL would pad it with 4 extra spaces.

The solution? Instead of looking up A2, look up TRIM(A2).

The TRIM() function removes leading and trailing spaces. If you have multiple spaces between words, TRIM converts them to a single space. In the figure below there are spaces before and after both names in A1. `=TRIM(A1)`

removes all but one space in A3.

By the way, what if the problem had been trailing spaces in column F instead of column A? Add a column of TRIM() functions to E, pointing to column F. Copy those and paste as values in F to make the lookups start working again.

The other very common reason that VLOOKUP won’t work is shown here. Column F contains real numbers. Column A holds text that looks like numbers.

Select all of column A. Press `Alt+D`, `E`, `F`. This does a default Text to Columns operation and converts all text numbers to real numbers. The lookup starts working again.

If you want the VLOOKUP to work without changing the data, you can use `=VLOOKUP(1*A2,...)`

to handle numbers stored as text or `=VLOOKUP(A2&"",...)`

when your lookup table has text numbers.

*VLOOKUP was suggested by Rod Apfelbeck, Patty Hahn, John Henning, @ExcelKOS, and @tomatecaolho. Thanks to all of you.*

*Title Photo: Ludovic Gauthier at Unsplash.com*