Automatic list merging

Bartekelese

New Member
Joined
Jan 25, 2022
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
Hello, I have many tables of many tools. Everyone can add new table by userform (inserting new sheet) . Every table has the same amount of columns with the same column names. There is one table per one sheet. I'm preparing to have about 100 sheets in this file. Every sheet name starts with 'XMX' and the rest is the number. There is only 4 additional sheets for areas, categories etc.
Is there any possibility to automaticly merge all tables into one table?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi and welcome to MrExcel

Try the following code. Just fit the name of the sheet and the table to do the merge.

VBA Code:
Sub MergeAllTables()
  Dim sh As Worksheet
  Dim tb1 As ListObject, tb2 As ListObject
  Dim lr As Long
  
  'Sheet and table name to consolidate all tables
  Set tb2 = Sheets("Consolidate").ListObjects("MergeTable")
  
  For Each sh In Sheets
    If LCase(Left(sh.Name, 3)) = LCase("XMX") Then
      For Each tb1 In sh.ListObjects
        tb2.ListRows.Add AlwaysInsert:=True
        lr = tb2.DataBodyRange.Rows.Count
        tb1.DataBodyRange.Copy tb2.ListRows(lr).Range
      Next
    End If
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

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