VLOOKUP with Numbers and Text: Fixes & Examples
In this article
VLOOKUP can match numbers and text, but it often fails when the lookup value is a number and the table contains text (or vice versa). This article explains why those mismatches happen, how to fix them, and how to use VLOOKUP reliably with mixed data types in Excel and Google Sheets.
in lookup | Lookup value | - | 12345 | 0 in table | Table array | - | A:B | 0 out result | VLOOKUP result | - | IF(ISNUMBER(lookup), VLOOKUP(TEXT(lookup,"0"), table, 2, FALSE), VLOOKUP(lookup, table, 2, FALSE)) | 0
Why VLOOKUP Fails with Numbers and Text
VLOOKUP compares values exactly as they are stored in the cell. A number like 12345 is stored as a numeric value, but if the lookup table has "12345" as text (often because of leading zeros, imported data, or cells formatted as text), the two are not considered equal. Excel and Google Sheets treat 12345 (number) and "12345" (text) as different values, so VLOOKUP returns #N/A even though they look identical.
This is the most common cause of VLOOKUP errors with numbers and text. The fix is to make both sides the same type: either convert the lookup value to text, or convert the table column to numbers.
How VLOOKUP Handles Data Types
VLOOKUP uses the first column of the table array to search for the lookup value. It does not automatically convert types. If the lookup value is a number and the first column contains text, it will not match. Conversely, if the lookup value is text (e.g., "00123") and the first column contains numbers (e.g., 123), it also fails.
There are two common scenarios:
- Number lookup, text table: The lookup value is a number, but the table column is formatted as text (often because of leading zeros or imported data).
- Text lookup, number table: The lookup value is text (e.g., an ID with leading zeros), but the table column is numeric.
In both cases, you need to align the types before VLOOKUP can work.
How to Fix VLOOKUP with Numbers and Text
Here are the most reliable fixes, from simplest to most robust:
- Convert the lookup value to text: Use
TEXT(lookup_cell, "0")to turn a number into text. This works when the table column is text. For example:=VLOOKUP(TEXT(A2,"0"), B:C, 2, FALSE) - Convert the table column to numbers: Use
VALUE()on the first column if it is text but contains numbers. However, this requires an array formula or a helper column because VLOOKUP cannot transform the table array on the fly. - Use a helper column: Add a column that converts the first column to the same type as your lookup value. For example, if your IDs are numbers but stored as text, add a column with
=VALUE(A2)and use that as the new first column. - Use INDEX/MATCH with a type conversion:
=INDEX(C:C, MATCH(TEXT(A2,"0"), B:B, 0))– this is more flexible and avoids the VLOOKUP table array limitation.
For Google Sheets, the same functions work. You can also use TO_TEXT() or VALUE() in a helper column.
Common Mistakes and Pitfalls
- Forgetting the exact match argument: Always use
FALSE(or0) for exact match when dealing with IDs or codes.TRUE(approximate match) will return wrong results. - Leading zeros: If your IDs have leading zeros (like
00123), they must be stored as text. If you enter them as numbers, Excel strips the zeros. Use text format or an apostrophe before the number. - Numbers formatted as text with trailing spaces: Sometimes text looks like a number but has invisible spaces. Use
TRIM()to clean it. - Using the wrong column index: The column index number counts from the first column of the table array, not the sheet. Double-check that.
VLOOKUP vs. INDEX/MATCH for Mixed Types
VLOOKUP is simpler but has limitations: it can only look to the right, and it cannot transform the lookup column. INDEX/MATCH (or XLOOKUP in newer Excel) is more flexible and often better for mixed data types because you can wrap the lookup value or the lookup array in TEXT() or VALUE() without needing a helper column.
For example, to look up a number in a text column, you can use:
=INDEX(C:C, MATCH(TEXT(A2,"0"), B:B, 0))
This works because MATCH accepts a converted value. In Excel 365, XLOOKUP also allows you to do this directly with a similar approach.
How to Prevent Data Type Mismatches
The best fix is to keep your data consistent from the start:
- Format ID columns as text before entering data, especially if they contain leading zeros.
- When importing from CSV or other sources, check the column types and convert them appropriately.
- Use Excel's Text to Columns or VALUE() to convert a column to numbers if needed.
- Use the ISTEXT and ISNUMBER functions to audit your data and find mismatches.
Frequently Asked Questions
Why does VLOOKUP return #N/A even though the values look the same?
Because one is a number and the other is text. Excel and Google Sheets treat them as different. Check the cell format: if the cell is left-aligned by default, it is likely text; if right-aligned, it is a number. Use ISTEXT() or ISNUMBER() to confirm.
How do I convert a number to text in VLOOKUP?
Use TEXT(lookup_cell, "0") as the lookup value. For example, =VLOOKUP(TEXT(A2,"0"), B:C, 2, FALSE). This forces the number to be treated as text, matching a text column.
How do I convert text to a number in VLOOKUP?
You cannot convert the table column directly inside VLOOKUP. Instead, create a helper column with =VALUE(A2) and use that as the first column of your table array. Then VLOOKUP with a numeric lookup value will work.
Does VLOOKUP work with leading zeros?
Only if both sides are text. If you have IDs like 00123, store them as text. If they are stored as numbers, Excel removes the leading zeros, so you must format them as text or use a custom format like 00000 to display them, but the underlying value is still numeric.
What is the best alternative to VLOOKUP for mixed data types?
INDEX/MATCH is more flexible because you can convert the lookup value or the lookup array on the fly. XLOOKUP (in Excel 365) is even simpler and supports this directly. For example, =XLOOKUP(TEXT(A2,"0"), B:B, C:C).
Can I use VLOOKUP with wildcards for text and numbers?
Yes, but only with text. Wildcards like * and ? do not work with numbers. If you need to match partial text, use VLOOKUP("*"&A2&"*", B:C, 2, FALSE) – but this only works if the lookup column is text.