VBA to merge 2 tables across many sheets

jessicabl

New Member
Joined
Sep 5, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Please see screenshots below. I received similar file every month with many tabs. In each tab, there are 2 tables (Table 1 and 2). I concatenate the ID (Column A) and Team Number (Column B) and use this concatenated identifier to merge the 2 tables. There are many columns in Table 1. In the screenshot, only a few columns are displayed.
Can you advise what is the VBA Code to merge these 2 tables into 1 table and output the data into a consolidated worksheet within the same file (see Table 3). I need to create a new column in column A and drop the tab name in, which is the name of the Salesperson. Preferably to sort the merged table by ID and Date. Repeat for the rest of the tabs.
 

Attachments

  • pic1.jpg
    pic1.jpg
    70.3 KB · Views: 2

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
With Power Query

Book1
ABCDEFGHIJ
1IDTeam NumberDateSales VolumeIDTeam NumberAreaUnit Sold
212345A15/1/20243 mil12345B2East2
312345B22/2/20247 mil12345C3North1
412345C37/1/20245 mil
5
6IDTeam NumberDateSales VolumeAreaUnit Sold
712345A15/1/20243 mil
812345B22/2/20247 milEast2
912345C37/1/20245 milNorth1
Sheet1


Power Query:
let
    T1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    T2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    MQ = Table.NestedJoin(T1, {"Team Number"}, T2, {"Team Number"}, "T3", JoinKind.FullOuter),
    #"Expanded T3" = Table.ExpandTableColumn(MQ, "T3", {"Area", "Unit Sold"}, {"Area", "Unit Sold"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded T3",{{"Date", type date}})

in
    #"Changed Type"
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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