by Svetlana Cheusheva, updated on
In this tutorial, you will find some tricks on merging Excel tables by matching data in one or more columns as well as combining worksheets based on column headers.
When analyzing data in Excel, how often do you have all necessary information gathered in a single worksheet? Almost never! It is a very common situation when different pieces of data are dispersed across many worksheets and workbooks. Fortunately, there are a few different ways to combine data from multiple tables into one, and this tutorial will teach you how to do this quickly and effectively.
Whatever task you need to perform in your worksheets, where do you look for a solution in the first place? Like many users, I usually go to the Formulas tab and open a list of functions. Merging tables is no exception :)
If you are to merge two tables based on one column, VLOOKUP is the right function to use.
Supposing you have two tables in two different sheets: the main table contains the seller names and products, and the lookup table contains the names and amounts. You want to combine these two tables by matching data in the Seller column:
As you see, the order of the names in the main table does not correspond with that in the lookup table, therefore a simple copy/pasting technique won't work.
To combine two tables by a matching column (Seller), you enter this formula in C2 in the main table:
Copy the formula down the column, and you will get a merged table consisting of the main table, plus the matched data pulled from the lookup table:
Please be aware that Excel VLOOKUP has several limitations, the most critical of which are 1) inability to pull data from a column to the left of the lookup column and 2) a hardcoded column number breaks a formula when you add or remove columns in the lookup table. On the bright side, you can easily reorder the returned columns simply by changing the number in the col_index_num argument.
Tip. If you have an Excel 365 subscription, then you can use a more powerful successor of VLOOKUP - Excel XLOOKUP function.
If you are looking for a more powerful and versatile alternative to the VLOOKUP function, embrace this INDEX MATCH combination:
The syntax is explained in detail in this tutorial: INDEX / MATCH in Excel. And here I will show you how to use this formula to look up from right to left, something that VLOOKUP is unable to do.
Let's say you have another lookup table with order IDs in the first column and you wish to copy those IDs to the main table by matching the seller names. For better visualization, both tables are put on the same sheet:
To accomplish the task, you supply the following arguments to the Index Match formula:
Please notice the $ sign that locks the ranges to prevent them from changing as you copy the formula down the table:
The completed formula looks as follows:
=INDEX($E$2:$E$10, MATCH($A2, $F$2:$F$10, 0))
…and combines data from two tables perfectly:
In Excel 365, you can use the new XLOOKUP function for the same purpose:
=XLOOKUP(A2, $F$2:$F$10, $E$2:$E$10, "Not found")
If the two tables you wish to join do not have a unique identifier, such as an order id or SKU, you can match values in two or more columns by using this formula:
Note. It is an array formula, so please remember to press Ctrl + Shift + Enter to enter it correctly.
The formula's breakdown can be found here: Look up with multiple criteria. For now, let's focus on the practical usage.
Assuming you have the following two tables to be combined into one. Because the Order ID column is missing in the lookup table, the only way to match the orders is by Seller and Product:
Based on the above screenshot, let's define the arguments for our formula:
Again, be sure to fix all the ranges with absolute cell references so that they won't change when you copy the formula down:
=INDEX($F$2:$H$9, MATCH(1, ($B2=$F$2:$F$9) * ($C2=$G$2:$G$9), 0), 3)
Enter the formula in D3, press Ctrl + Shift + Enter, copy it to the below rows and check the result:
To have a closer look at the above examples and probably reverse-engineer the formulas, you are welcome to download our sample workbook to Merge Two Tables in Excel.
In situations when you need to combine two or more tables with different numbers of rows and columns, Excel Power Query may come in handy. However, please be aware that joining tables with Power Query cannot be done with a mere couple of clicks. Explaining all the nuances would take far more space than we have here, so I will just briefly outline the main features:
The detailed guidance can be found in this tutorial: How to join tables with Excel Power Query.
If you are not very comfortable with Excel formulas yet, nor do you have time to figure out the arcane quirks of Power Query, our Merge Tables Wizard could be your time-saver. Below I will show three most popular uses cases.
If you find the array formula for columns match hard to remember, rely on our add-in to do the job quickly and perfectly.
For this example, we will be using the already familiar tables and join them based on 2 columns, Seller and Product. Please note that the lookup table has 2 more columns than the main table:
With the Merge Tables Wizard added to your Excel ribbon, here's what you need to do:
Tip. If the text case in the key columns matters, check the Case-sensitive matching box to treat uppercase and lowercase as different characters.
The default options work just fine in our case, so we click Finish without changing anything:
Allow the wizard a few seconds for processing and review the result:
As you can see in the screenshot above, the wizard has done the following:
In case your main table contains some outdated data, you can have it updated with the corresponding values from the lookup table.
As an example, let's merge 2 tables by Order ID and update the values in the Price column:
To get the result shown in the above image, this is what you need to do:
Step 1. Select the main table.
Step 2. Select the lookup table.
Step 3. Choose Order ID as the matching column.
Step 4. Select Price as the column to update.
Step 5. Skip it because there are no columns to add.
Step 6. Since there are a few gaps in the New price column, we choose to update only if cells in the lookup table contain data. Optionally, you can highlight the updated cells with any color of your choosing. The screenshot below shows the settings:
Tip. To prevent overwriting your existing data, you can update only empty cells in the main table.
In situations when a lookup table contains several occurrences on the lookup value, you may want to pull them all to your main table. The task can be accomplished with one of the non-trivial array formulas described in Vlookup to return multiple matches in Excel. Or you can do it the easy way with the Merge Tables Wizard.
Supposing your main table contains just one order of each seller, and the lookup table contains additional orders. Now you want to combine all the orders in one table, grouped by seller name like this:
Looks like a lot of work to do? Not if you have the Merge Tables Wizard at your disposal :)
Step 1. Select the main table.
Step 2. Select the lookup table.
Step 3. Choose Seller as the column to match.
Step 4. Update Order ID and Product.
Step 5. There are no columns to add.
Step 6. Insert additional matching rows after the row with the same key value. Optionally, set a background color for added rows to review the changes with a quick glance:
The above examples show just 3 of many possible ways to join tables in Excel. If you are curious to see other scenarios that the Merge Table Wizards can handle, please check out the visuals on this page. Or you can download a 30-day trial version and give it a shot.
In the above examples, we were merging two tables that have identical columns and pulling data from one table to another. In case you want to join multiple tables from different sheets into one based on columns headers, our Combine Sheets add-in is the right tool for the job.
The below image shows the source tables and desired result:
And here's how you can accomplish the task:
If you'd like to combine just one table, not all data, hover over the sheet's name, and then click the Collapse dialog icon on the right to select a range:
Done! The three tables are combined into one exactly like shown in the beginning of this example.
The Merge Tables Wizard and Combine Sheets are the most popular tools to join tables in Excel. If you have some other task in mind, chances are that you will also find a quick solution on the Ablebits Data tab:
Let me briefly describe what each of these add-ins does:
Merge Two Tables - joins two tables that have one or more identical columns, as shown in these examples.
Combine Sheets - merges multiple worksheets into one based on column headers, like we did a moment ago in this example.
Merge Duplicates - combines duplicate rows by key columns.
Consolidate Sheets - joins tables together and summarizes their data.
Copy Sheets - provides 4 different ways to merge sheets in Excel.
Merge Cells - merge cells, columns, and rows without losing data, even if a selection contains multiple values.
Vlookup Wizard - quick way to build a Vlookup or Index/Match formula best suited for your data set.
Compare Sheets - find, highlight, and merge differences between two worksheets.
Compare Multiple Sheets - highlight differences in two or more sheets.
All the above features as well as 70+ other time-saving tools are included with our Ultimate Suite for Excel. An evaluation version is available for download right below this post. I thank you for reading and hope to see you on our blog next week!
Ultimate Suite 14-day fully-functional version (.exe file)
Table of contents