Function Problems

Map Text Codes to Numbers in Excel with a Lookup

Tauseeq MagsiTauseeq Magsi Dec 2, 2026 869 views

Question details

Return a numeric value based on a text code entered in a spreadsheet cell.

Map Text Codes to Numbers in Excel with a Lookup
Product
Microsoft Excel
Device & OS
not provided
Scenario
The user wants to maintain a list of text codes and their corresponding values, potentially from 1 through 5.
Observed behavior
A lookup formula returns the number associated with the entered code or a message when no match is found.
Before you start

Choose an input cell and two empty columns for the lookup table. Check that each code has the intended numeric value and that the formula ranges cover all table rows.

Solution 1Recommended

Use XLOOKUP with a Two-Column Code Table

Use this method in Microsoft 365 to return a value from an easy-to-update lookup table.

1
Create the lookup table

Enter codes in H2:H20 and their corresponding numbers in I2:I20. For example, enter TL and UA with 1, WW with 2, and UI with 3.

2
Enter a code

Type a code such as TL in cell B2.

3
Add the lookup formula

Select the result cell, such as C2, and enter =XLOOKUP(B2,$H$2:$H$20,$I$2:$I$20,"No match"). Press Enter.

4
Apply it to other rows

Drag the fill handle from C2 down to calculate results for codes in column B. Add or change mappings in columns H and I as needed.

Use XLOOKUP with a Two-Column Code Table
Keep the ranges current: If your table extends beyond row 20, update both lookup ranges to include the additional rows. An unmatched code returns the text "No match".
WPS Spreadsheets

Map Text Codes to Numbers in WPS Spreadsheets

Create the same two-column lookup table in WPS Spreadsheets and use VLOOKUP with IFERROR to return a number for each code.

  1. 1. Open your workbook: Open WPS Spreadsheets and select Open to choose your workbook.
  2. 2. Create the mapping table: Enter codes in H2:H20 and their corresponding numbers in I2:I20.
  3. 3. Enter a lookup formula: Select C2 and enter =IFERROR(VLOOKUP(B2,$H$2:$I$20,2,FALSE),"No match"). Press Enter.
  4. 4. Copy and save: Drag the fill handle from C2 down for other input rows, then select Save to keep your changes.
Maintain code-to-number mappings in a separate lookup tableOpen and edit Microsoft Excel XLSX and XLS filesCopy the lookup formula down a column for multiple codesUse a familiar spreadsheet interface
microsoft office alternative - wps office

Frequently Asked Questions

How do I return a message when a code is not in the table?

In XLOOKUP, use the fourth argument, as in =XLOOKUP(B2,$H$2:$H$20,$I$2:$I$20,"No match"). With VLOOKUP, wrap the formula in IFERROR to display the message.

Why does VLOOKUP return the wrong value?

Check that the codes are in the first column of H2:I20, the numbers are in the second column, and the formula ends with FALSE for an exact match.

Can several codes return the same number?

Yes. Enter each code on its own row in column H and repeat the appropriate number in column I.

What should I do when I add more codes below row 20?

Extend the formula ranges to include the new rows. For example, change $H$2:$I$20 to $H$2:$I$30 in the VLOOKUP formula.