Join Tables

22strider

Active Member
Joined
Jun 11, 2007
Messages
311
Hello Friends

Could you please help me with VBA Code for joining two tables on a common column and then generate a third table. Both the tables are on a separate worksheet and the result table needs to be on a separate sheet as well. I can easily do this using Access but my requirement is to use Excel. I am using Excel 2007.
Following are the tabls showing sample data; Table1 and Table2 are the source tables having Manufacturer P/N as the common column. And Result Table is showing how the joined table should look like.
Thanks for your help
Rajesh



Excel 2007
ABCDE
1Table1
2P/NManufacturer P/NManufacturer Name
3500-123700-ABCABC
4500-123700-DEFDEF
5500-546600-XYZXYZ
6500-546600-PQRPQR
7400-123700-ABCABC
8
9
10Table2
11Manufacturer P/NManufacturer NameCountryType
12700-ABCABCUSASupplier
13700-DEFDEFChinaManufact.
14600-XYZXYZIndiaSupplier
15600-PQRPQRUSADesigner
16
17
18
19Result Table
20P/NManufacturer P/NManufacturer NameAddressType
21500-123700-ABCABCUSASupplier
22500-123700-DEFDEFChinaManufact.
23500-546600-XYZXYZIndiaSupplier
24500-546600-PQRPQRUSADesigner
25400-123700-ABCABCUSASupplier
26
Sheet1
 
And this can be placed in worksheet 1 if you want that it works on change

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'If change in first worksheet has filled all 3 fields then call macro Joiner
Lastcell = WorksheetFunction.CountA(Columns(1))
If Range("A" & Lastcell).Offset(0, 1).Value = "" Then Exit Sub
If Range("A" & Lastcell).Offset(0, 2).Value = "" Then Exit Sub
Call Joiner
End Sub
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Rajesh,

I checked again on my side and the code works fine. It could be the names and/or ranges in your workbook. Otherwise post a sample of what goes wrong.
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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