I have a 2D table of names. I have a second table with 2 columns where each name (first column) has a value corresponding to it in the second column. Now I want to have a third table with the same structure as my 2D name table, where each name is replaced by its value. How can I do this in Excel without a Macro?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
You can absolutely do this in Excel without using any macros, using lookup functions like VLOOKUP or XLOOKUP (if you have a newer version of Excel).
Let's assume the following setup:
Table 1 (2D Name Table): This table is located on Sheet1 starting in cell A1.
Example:
code
Sheet1
A B C
1 Bob Alice Charlie
2 David Eve Frank
Table 2 (Name-Value Lookup Table): This table is located on Sheet2 starting in cell A1. The first column contains the names, and the second column contains their corresponding values.
Example:
code
Sheet2
A B
1 Alice 10
2 Bob 20
3 Charlie 30
4 David 40
5 Eve 50
6 Frank 60
Table 3 (Result Table): You want this table to have the same structure as Table 1, but with values instead of names. You can place this on a new sheet (e.g., Sheet3) or next to Table 1 (e.g., starting in E1 on Sheet1). Let's assume Sheet3!A1 for clarity.
Method 1: Using VLOOKUP (Most Common and Widely Compatible)
Go to the first cell of your Result Table.
In our example, go to Sheet3!A1.
Enter the VLOOKUP formula:
=VLOOKUP(Sheet1!A1, Sheet2!$A:$B, 2, FALSE)
Let's break down this formula:
Sheet1!A1: This is the lookup_value. It's the first name from your 2D name table that you want to look up.
Sheet2!$A:$B: This is the table_array. It's your entire lookup table (names in column A, values in column B on Sheet2). The $ signs are crucial here – they create an absolute reference, meaning that when you drag the formula, this range will not change. If you only had specific rows with data (e.g., A1:B6), you would use Sheet2!$A$1:$B$6. Using $A:$B covers the entire columns, which is usually safer if your lookup table might grow.
2: This is the col_index_num. It tells VLOOKUP to return the value from the second column of your table_array (Sheet2!$A:$B), which is where your values are.
FALSE: This is the range_lookup. It specifies that you want an exact match. If the name isn't found, it will return #N/A.
Press Enter. You should see the value for "Bob" (which is 20) appear in Sheet3!A1.
Drag the formula:
Click on cell Sheet3!A1.
Hover your mouse over the small green square at the bottom-right corner of the cell (the "fill handle"). Your cursor will change to a black plus sign.
Click and drag the fill handle across to the right (Sheet3!C1 in our example) to fill the first row.
Then, with the entire first row (Sheet3!A1:C1) selected, click and drag the fill handle down to fill the remaining rows (Sheet3!A2:C2).
Now, Sheet3 will mirror the structure of Sheet1 but contain the corresponding values from Sheet2.
Method 2: Using XLOOKUP (Excel 365, Excel 2019, Excel for the web)
XLOOKUP is a more modern and powerful lookup function. If you have it, it's often preferred.
Go to the first cell of your Result Table.
In our example, go to Sheet3!A1.
Enter the XLOOKUP formula:
=XLOOKUP(Sheet1!A1, Sheet2!$A:$A, Sheet2!$B:$B, "#N/A Not Found", FALSE)
Let's break down this formula:
Sheet1!A1: This is the lookup_value (the name from your 2D table).
Sheet2!$A:$A: This is the lookup_array. It's the column in your lookup table where XLOOKUP will search for the name (Column A on Sheet2). Again, $A:$A makes it an absolute reference.
Sheet2!$B:$B: This is the return_array. It's the column from which XLOOKUP will return the corresponding value once it finds the name (Column B on Sheet2).
"#N/A Not Found": This is the optional [if_not_found] argument. If the name is not found in Sheet2!$A:$A, this text will be displayed instead of the default #N/A error. You can omit this if you're fine with #N/A.
FALSE: This is the optional [match_mode] argument, specifying an exact match.
Press Enter.
Drag the formula as described in Step 4 for VLOOKUP.
Handling Names Not Found (Error Management)
If some names in your 2D table might not exist in your lookup table, the VLOOKUP or XLOOKUP formulas will return #N/A. You can wrap your formula in IFNA (or IFERROR for older versions) to display something more user-friendly:
Using IFNA (Excel 2013 and later):
=IFNA(VLOOKUP(Sheet1!A1, Sheet2!$A:$B, 2, FALSE), "Name Not Found")
or
=IFNA(XLOOKUP(Sheet1!A1, Sheet2!$A:$A, Sheet2!$B:$B), "Name Not Found")
(Note: for XLOOKUP, you could also use its built-in if_not_found argument as shown above)
Using IFERROR (Excel 2007 and later):
=IFERROR(VLOOKUP(Sheet1!A1, Sheet2!$A:$B, 2, FALSE), "Name Not Found")IFERROR catches any error, not just #N/A, so it's a bit broader.
Choose the method that suits your Excel version and preferences. Both will achieve your goal without macros!