Macro to Merge tables 1:M relationship

Gimics

Board Regular
Joined
Jan 29, 2014
Messages
164
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am looking for some help to combine two tables of separate data based on a single column with a 1:M relationship. I do not have power pivot, so I am defaulting to vba as the best option (unless I hear otherwise).

Example:

The two tables share Group as a common Key - the macro should create a new table, joining both on group and extending to include both values. I do have other columns of data in each table, but they would be simple additions to the result and do not affect the join.

Table 1
AccountGroup
50000Apple
50000Plum
50000Pear
60000Apple
60000Plum
60000Pear

<tbody>
</tbody>


Table 2
GroupCenter
Apple1000
Apple2000
Apple3000
Plum2000
Plum2500
Plum3000
Pear1000
Pear2500
Pear3000

<tbody>
</tbody>


Expected result:
AccountGroupCenter
50000Apple1000
50000Apple2000
50000Apple3000
50000Plum2000
50000Plum2500
50000Plum3000
50000Pear1000
50000Pear2500
50000Pear3000
60000Apple1000
60000Apple3000
60000Apple2000
60000Plum2000
60000Plum2500
60000Plum3000
60000Pear1000
60000Pear2500
60000Pear3000

<tbody>
</tbody>


Thanks in advance!
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Are your tables real Excel Table objects or just ranges of cells that you think of as a table? If the former, are the table names really Table1 and Table2? If the latter, what is the addresses of your two table ranges?
 
Upvote 0
Are your tables real Excel Table objects or just ranges of cells that you think of as a table? If the former, are the table names really Table1 and Table2? If the latter, what is the addresses of your two table ranges?

Hey Rick - they are real table objects with table names "Table1" and "Table2". If it's easier to use the range addresses, they both start at 1,1 of two separate worksheets (Sheet1 and Sheet2).

Thanks
 
Upvote 0
Anyone with any insights? I was thinking of using "for" loops with 'find' lookups and storing the found ranges then cycling through everything, for each item in the original table... but there's gotta be a simpler way!
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,309
Members
449,095
Latest member
Chestertim

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top