Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conditionally merge/join excel worksheets?

+---------+---------+  +---------+--------------+  +---------+-------------+
+ country + widgets +  + country + frammis rods +  + country + comex gears +
+---------+---------+  +---------+--------------+  +---------+-------------+
+ alpha   +       1 +  + bravo   +            8 +  + charlie +          18 +
+ bravo   +       3 +  + charlie +           16 +  + delta   +           9 +
+ charlie +       7 +  + delta   +           32 +  +---------+-------------+
+ delta   +      11 +  +---------+--------------+
+---------+---------+

I have several Excel worksheets like these ^^^ within the same spreadsheet. I'm trying to create a new worksheet that contains merged data showing only those countries with data in all the worksheet categories.

E.g.,

+---------+---------+--------------+-------------+
+ country + widgets + frammis rods + comex gears +
+---------+---------+--------------+-------------+
+ charlie +       7 +           16 +          18 +
+ delta   +      11 +           32 +           9 +
+---------+---------+--------------+-------------+

I'm looking for a fairly simple, flexible way of doing this as the various worksheets are updated / new worksheets are added. I know how to do this in MYSQL, but I'm not sure if its possible in excel.

So, what do the experts have to say?

Thx in advance. :)

like image 257
phpwns Avatar asked Jan 31 '13 23:01

phpwns


People also ask

How do I merge two Excel spreadsheet Data based on some conditions?

On the Data tab, under Tools, click Consolidate. In the Function box, click the function that you want Excel to use to consolidate the data. In each source sheet, select your data, and then click Add.

How do I consolidate Data from multiple worksheets in Excel?

In the Function box, click the summary function that you want Excel to use to consolidate the data. The default function is SUM. Select your data. Next, in the Reference box, click the Collapse button to shrink the panel and select the data in the worksheet.

How do I merge multiple Excel files in one workbook but in different sheets?

You don't even have to open all of the workbooks you want to combine. With the master workbook open, go to the Ablebits Data tab > Merge group, and click Copy Sheets > Selected Sheets to one Workbook. In the Copy Worksheets dialog window, select the files (and optionally worksheets) you want to merge and click Next.


1 Answers

First off, thanks to @MikeD for an AWESOME writeup on a solution using pivot tables. I did manage to get that working in Excel 2007.

However, I decided to use a SQL query since its MUCH faster. (Yes, you can use SQL to merge worksheets. Sweet!)

1) Data --> From Other Sources --> From Microsoft Query

2) Choose Data Source --> Excel Files* --> Leave "Use the Query Wizard to create/edit queries" Checked

3) Select Workbook

4) Choose the columns you want --> click next --> Click "OK" on the pop-up warning you of the need to setup a manual join

enter image description here

5) In the "Microsoft Query" window --> Table --> Joins

enter image description here

6) Click on the "Return Data" icon

enter image description here

7) Import Data --> CTL + Click the column headers of the duplicates (e.g., "Country2," "Country3") --> Right Click --> "Hide"

enter image description here

8) !

enter image description here

like image 200
phpwns Avatar answered Oct 30 '22 04:10

phpwns