Match a Location to Its Code in Excel with INDEX MATCH or XLOOKUP
Question details
Return the code for a candidate’s current location by matching it to a location reference table.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A candidate table contains current locations, and a separate reference table maps each location to a code.
- Observed behavior
- Each candidate’s row should show the code associated with its current location.
Check that the reference table has a place column and a corresponding code column, and that location names match the candidate data. If using structured references, confirm that the reference table is named Table1 and the columns are named place and code.
Use INDEX MATCH to Return the Location Code
Use an exact-match formula with structured Excel tables to retrieve the code for each candidate.
In the candidate table, select the first cell in the column where you want the location code to appear.
Type =INDEX(Table1[code],MATCH([@[current location]],Table1[place],0)) and press Enter. The MATCH function finds the exact location, and INDEX returns the corresponding code.
If Excel does not fill the table column automatically, drag the cell’s fill handle down through the remaining candidate rows.

Use XLOOKUP to Match Locations and Codes
Use XLOOKUP in Microsoft 365, Excel 2021, or a later version to return a custom message when a location is missing.
Look Up Location Codes with WPS Spreadsheets
Use INDEX and MATCH in WPS Spreadsheets to find a candidate’s location in a reference list and return the corresponding code.
- 1. Open the workbook: Open your workbook in WPS Spreadsheets. For this example, place candidate locations in column B and location codes in column C.
- 2. Check the reference sheet: On Sheet2, place reference locations in A2:A100 and their corresponding codes in B2:B100. Adjust these ranges if your reference list is elsewhere.
- 3. Enter the lookup formula: On the candidate sheet, select C2, enter =INDEX(Sheet2!$B$2:$B$100,MATCH(B2,Sheet2!$A$2:$A$100,0)), and press Enter.
- 4. Fill down: Drag the fill handle from C2 down column C to return codes for the other candidates.

Frequently Asked Questions
Why does INDEX MATCH return #N/A for a location?
The location was not found as an exact match. Compare the candidate’s current location with Table1[place] for spelling differences and extra spaces.
Can I use VLOOKUP instead?
Yes. If Table1 has place as its first column and code as its second, enter =VLOOKUP([@[current location]],Table1,2,FALSE) in the candidate table.
What happens if the reference table contains the same location more than once?
The formulas shown return the code for the first matching location. Check Table1[place] for duplicates if each location should have only one code.
How do I use these formulas without Excel table references?
Replace the structured references with cell ranges. For example, if the candidate location is in B2 and Sheet2 contains places in A2:A100 and codes in B2:B100, use =INDEX(Sheet2!$B$2:$B$100,MATCH(B2,Sheet2!$A$2:$A$100,0)).




