VBA Code to merge excel worksheets:
1. Hold
down the ALT + F11 keys,
and it opens the Microsoft
Visual Basic for Applications window.
2.
Click Insert > Module, and paste
the following code in the Module Window.
Sub Combine()Dim J As IntegerOn Error Resume NextSheets(1).SelectWorksheets.AddSheets(1).Name = "Combined"Sheets(2).ActivateRange("A1").EntireRow.SelectSelection.Copy
Destination:=Sheets(1).Range("A1")For J = 2 To Sheets.CountSheets(J).ActivateRange("A1").SelectSelection.CurrentRegion.SelectSelection.Offset(1,
0).Resize(Selection.Rows.Count - 1).SelectSelection.Copy
Destination:=Sheets(1).Range("A65536").End(xlUp)(2)NextEnd Sub
Notes:
(1) Your data must start from A1, if not, the code will not take effect.
(2) Your data must have the same structure.
(3) This code only can combine all worksheets of the active workbook, if you want to merge worksheets from multiple workbooks, this code will not work.
(1) Your data must start from A1, if not, the code will not take effect.
(2) Your data must have the same structure.
(3) This code only can combine all worksheets of the active workbook, if you want to merge worksheets from multiple workbooks, this code will not work.
No comments:
Post a Comment
Your feedback is always appreciated. I will try to reply to your queries as soon as time allows.Please don't spam,spam comments will be deleted upon reviews.