Excel - How to merge rows from 2 tables based on a common column?

2

1

I am trying to merge 2 worksheets where only one col matches in content.

Column"A" in both worksheets have matching values but all other fields are different.

Worksheet1:

Col"A" colb colc cold

(worksheet1 has 25,000 rows)

Worksheet2:

Col"A" cole colf colg

(worksheet2 has 22,000 rows - so some rows are missing)

NEW COMBINED WORKSHEET NEEDS TO LOOK LIKE THIS:

Col"A" colb colc cold cole colf colg (new worksheet has 25,000 rows)

How can I do this?

example illustration here: http://www.ablebits.com/office-addins-blog/2014/02/06/merge-rows-excel/#merge-matching-rows

user3368180

Posted 2014-08-26T16:52:26.003

Reputation: 23

Question was closed 2017-05-17T17:12:21.773

Answers

1

You need to use =vlookup() for that. Copy column A from the bigger sheet into Column A of a new sheet. Then us =vlookup(A1, [Worksheet1.xls]tab1!$A$1:$D$25000, 2, false) to build Column B. Rinse and repeat for the remaining columns changing up values in the vlookup function as needed.

JNevill

Posted 2014-08-26T16:52:26.003

Reputation: 1 198

Thanks. I will try this now. basically the result i want is like this... http://www.ablebits.com/office-addins-blog/2014/02/06/merge-rows-excel/#merge-matching-rows

– user3368180 – 2014-08-26T17:32:45.327

Vlookup should work. The trick is that every possible value for Column A needs to exist in the new worksheet. You could copy all of them from the larger sheet, and then use a countif function on the smaller sheet to see if there are any extra values that it has that they larger sheet doesn't. Then do the vlookup. – JNevill – 2014-08-26T18:49:53.563

2

I would use the Power Query Add-In for this. It has a Merge command that can handle this requirement without writing a single formula or any code.

http://office.microsoft.com/en-au/excel-help/merge-queries-HA104149757.aspx?CTT=5&origin=HA103993872

I hope it's not too late to switch - only 5 hours have passed so you are probably still editing vlookup formulas ...

Mike Honey

Posted 2014-08-26T16:52:26.003

Reputation: 2 119

1Yes it is very cool ad-ins. Thanks! – SIslam – 2015-09-21T07:31:28.383

2

You can use Query from Excel Files :

  • Define name for primary table dataset - Worksheet1 (Formulas tab -> Define name)
  • Define name for secondary table dataset - Worksheet2
  • Go to Data tab, select "From Other Sources", and from the dropdown, select "From Microsoft Query"
  • Select your workbook file and confirm that you want to merge the columns manually
  • In the following window "Query from Excel Files", drag&drop the Col "A" of first dataset into the Col "A" of second dataset - a link between these columns will be created
  • Go to File menu, click "Return Data to MS Office Excel", an Import Data dialog will pop up
  • Select the sheet into which you would like the matched data to be imported
  • Click OK -> you should see matched data with columns from both tables

Or if you don't mind uploading your files to an online service, you can use for example http://www.gridoc.com/join-tables and merge the tables using drag&drop (Disclaimer: I am author of the tool).

Hope this helps.

endriju

Posted 2014-08-26T16:52:26.003

Reputation: 249

0

Not sure if this is what you're after, but I would copy and paste the entire contents of both worksheets into one worksheet or new workbook, sort, and then use Excel's delete duplicates function, checking the column labels you want Excel to use for removing duplicates.

BillDOe

Posted 2014-08-26T16:52:26.003

Reputation: 1 413

thanks for answering, but how would i combine two rows, see http://www.ablebits.com/office-addins-blog/2014/02/06/merge-rows-excel/#merge-matching-rows

– user3368180 – 2014-08-26T17:10:57.140

Doing VLOOKUP on one row and getting the values you want from the other sheet ought to work. Just copy and paste values and delete the column with the VLOOKUP afterward. – BillDOe – 2014-08-26T17:23:09.993