Excel VLOOKUP – numbers as text & vice versa

Have you ever tried a VLOOKUP formula in Excel where you’re looking up something that is numeric but stored as text, or vice versa? So annoying, when you seem to have one set of data one way and the lookup in another, right? Today’s #TipTuesday is all about helping you with a couple of formula tweaks to make this a bit easier.

Example 1 – Text to Number

The first example is a simple table where I’m looking up something by year, and the year is stored as a number in this case (column A). In cell E3, I have a year in text format (note the top left corner has the green mark, visually identifying this as text). If I do the usual VLOOKUP formula, I get an #N/A, it can’t find a match to that.

How to fix

In this case, I want to use the VALUE formula which simply is going to return the “value” of that cell, which is the number “2016”. With that small change, and the rest of the formula staying the same, it now returns the proper value I’m looking for (# of returns for a given year).

Old formula: (spaces are for readability only)

= VLOOKUP ( cell , array , column number , FALSE )

New formula:

= VLOOKUP ( VALUE(cell) , array , column number , FALSE )

Example 2 – Number to Text

The opposite scenario also happens regularly, where the list/array is in text format but the value you want to look up is a number. I’m using the exact same data as I did in Example 1, except now the year is stored as text (again, note the green visual indicator in Column A’s values. In cell E3, I have a year in number format. If I do the usual VLOOKUP formula, I get an #N/A, but I cannot use a VALUE( ) formula to fix this one.

How to fix

In this case, I want to use the TEXT formula to “convert” the value to a text format before using the VLOOKUP command. The TEXT formula has 2 elements to it, what the cell reference is and then the format you want. Here is a link to help with different format options (link) but in this case, the simple answer is if it’s a number, you can use “0” for the text format.

Old formula:

= VLOOKUP ( cell , array , column number , FALSE )

New formula:

= VLOOKUP ( TEXT(cell, "0") , array , column number , FALSE )

Recap

The short version of this tip would be: if you are unable to make your array and the value you want to look up the same format (both numeric or both text), these are some easy ways to get the results you want quickly and easily. The trick is changing the format of the thing you’re looking up, not changing the “array” you are looking it up in!

Hopefully that makes sense and saves you some trouble in your formulas!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top