Vlookup – why do I need TRUE or FALSE?

In the last few days there has been a discussion about VLookup and how the last parameter works when it is entered as TRUE, FALSE or omitted altogether.

The Microsoft Help page was showing an example screenshot, where the formula and the result did not match up.

This was an oversight in the help documentation and will be fixed.

But it sparked a few questions, like:

  • Why do I get an error for this formula, but when I expand the lookup table by one row I get the correct result?


With the last parameter set to 0 or FALSE, Vlookup will go through the list from the top, one cell after the other, and will compare each value in the first column to the lookup value. The list does not need to be sorted. When it finds a match, it returns the value from the specified column. For large lists, this can be rather slow.

Vlookup with the 1 or TRUE as the last parameter (omitting the parameter defaults to TRUE), works differently. Vlookup will now assume/expect that the list is sorted ascending in the first column. In order to find the lookup value, it does not inspect each cell, but cuts the list in half. If the value at the half point is a match — Bingo! If not, it compares the value at the half point with the lookup value and decides: If the lookup value is greater than the value of the half point, then continue with toe lower half of the list. Cut the lower half of the list in half and see. If the lookup value is smaller than the value of the half point, then continue with the upper half of the list. Cut the upper part of the list in half and see.

So Vlookup will start with 1/2 of the list,  then reduce to 1/4 of the list, then to  1/8,  then 1/16, etc. until it finds the match. If it gets down to only one value, but that value is not an exact match, this value will be treated as the match and the corresponding column value will be returned.

Are your ears smoking yet? Let’s look at an example.

Consider this table


The formula in A12 is =VLOOKUP(“h”,A2:B10,2).

Vlookup will split the table in half and will look at the last value of the top half. If there is an uneven number of rows, it will grab the next row, too. So Vlookup will consider this range:


The table has 9 rows, so Vlookup looks at the fifth row of the data table.

With text values, “greater” and “smaller” refer to the position in an alphabetic sort. So “a” is smaller than “c” and “k” is greater than “c”.

The value “i” is greater than the search value “h”. Therefore, the desired value is above Excel row 6. Vlookup will then split this upper part of the table in half. Since there are 5 rows involved, the split will be done at the third row of the range:


Vlookup looks at Excel cell A4. This value “e” is smaller than the lookup value. That means that the value we want is not in the table range that was just inspectedd, so we can forget that part of the table. Next Vlookup looks at the lower half of the range from the previous step.


Again, the last value in that range is “i” and greater than the lookup value, so let’s split this range in half and look at the last row of the top half:


This range consists of one row only. There’s nothing more to split. The value is not an exact match, but the return column will be returned, anyway.

Vlookup with TRUE as the last parameter will deliver the value that is “equal to or smaller than” the lookup value.

Coming back to the example with the names at the top of the post:


The formula used is =VLOOKUP(“Akers”,B2:D5,2)

The range is split in half, the last value in the top half is greater than the lookup value, so the lower half of the table will not even be considered for further inspection. The top two rows will be split in half and a value smaller than “Carido” will be expected in the last cell of that next split. But the last value in a split has “Weiler” as the value. That is not smaller than the lookup value “Akers”. Hence an error is returned.

If we add one row to the lookup table range, the first pass of Vlookup will split the table of 5 rows in half, rounding up to contain the top three rows in the first pass. Now we use the formula

=VLOOKUP(“Akers”,B2:D6,2)


The value in cell B4 is a perfect match, so the value in column C is returned. Bingo! We have a correct result for an unsorted table, without the fourth parameter!

Magic? No, it is pure coincidence. Omitting the last Vlookup parameter on an unordered list MAY return the correct result, but the chances of that are rather slim.

In this case, it is pure luck that the lookup value matches the last entry of the range that Vlookup considers in this pass.

If you use Vlookup without the fourth parameter, you must ensure that the lookup table is sorted by the first column. Otherwise, any result you get back is as reliable as getting the lotto numbers from a toddler.

It may work, but in most cases it won’t.

8 comments

  1. tnx a lot for this tnx a lot for this very helpful! aecarpipte your help with the below two fold question:a) what if my worksheet names are not as consistent as in your example ? i.e. instead of region 1, 2, 3 I have alphanum codes such as AB1, DB2, CC3 for worksheet names. is there wild card’ variable make excel look in the next sheet irrespective of its name? b) is there a way to tell excel which is the first worksheet to vlookup into and which is the last ?

    Like

  2. = VLOOKUP(“DI-328”, A2:D6, 3, FALSE) * (1 + VLOOKUP(“DI-328”, A2:D6, 4, FALSE)) Why “FALSE” is used here?
    or =VLOOKUP(“Akers”,B2:D6,2) why “2” is used here?

    Like

    • False is used to find an exact match. The last formula omits the fourth parameter, which means it defaults to true. Why is False used in one and not in the other? Because an exact match is wanted in the first two, but not in the last one. Why? Well, without seeing the data and knowing the business logic, that is impossible to answer.

      Like

  3. I think this is a simple question since I am a novice. Instead of the word FALSE appearing, is there a way to substitute another word to be displayed.
    For example, if a date or value does not exist in a range is there a simple way to make the word NONE or words Not AVAILABLE be displayed instead.

    Thanks in advance!

    Like

    • Tom, Vlookup does not display the word “False” if a value does not exist. FALSE or TRUE is the boolean parameter for an exact match, as explained in the article. If a value does not exist, the error message #N/A will be displayed. To avoid that you can wrap the Vlookup in an IF() for IFERROR() statement.

      Like

Leave a comment