VBA - Merge all tabs with same header into a new tab

mabalo76

New Member
Joined
Apr 10, 2018
Messages
27
Hi,

Thanks in advance since i am pretty new to Excel VBA.

I have a excel file and contains multiple tabs with the same header. Each tab contains some data(The # of rows can vary). The data in each tab contains some formula.

What i want to do is to merge all the data from each tab together. When copy and paste, only paste the Value of the data. For example, copy all data in first tab (include header) into a new tab, then copy the second, third, ... tab data from the row 2 to the end of row(don't include header from tab2) and paste in the new tab at the end. Please note: only paste the value of the data, don't paste the functions.

Thanks,
Dan
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try:
Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Worksheets.Add(After:=Sheets(Sheets.Count)).Name = "Summary"
    Sheets(1).Rows(1).Copy Cells(1, 1)
    For Each ws In Sheets
        If ws.Name <> "Summary" Then
            ws.UsedRange.Offset(1, 0).Copy
            Sheets("Summary").Cells(Sheets("Summary").Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
        End If
    Next ws
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this:

Code:
Sub Merge_all_tabs()
  Set sh = Worksheets.Add(After:=Sheets(Sheets.Count))
  sh.Name = "New tab"
  Sheets(1).Rows(1).Copy sh.Rows(1)
  For i = 1 To Sheets.Count - 1
      u = sh.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count)(2).Row
      sh.Range("A" & u).Resize(Sheets(i).UsedRange.Rows.Count, Sheets(i).UsedRange.Columns.Count).Value = Sheets(i).UsedRange.Offset(1).Value
  Next
End Sub
 
Upvote 0
An alternative solution would be to load each tab into Power Query and then Append each tab. A quick and easy step that does not require any coding.
 
Upvote 0
Hi there,
Is there a way to do this but instead of pasting values, paste as a link so that any changes made in the source sheet will reflect in the target sheets?
 
Upvote 0
In Power Query, any changes in the source documents are automatically updated in the output.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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