Skip to content

Instantly share code, notes, and snippets.

@compustar
Created February 1, 2020 09:34
Show Gist options
  • Save compustar/14508196a1486b2548d41e55e54af8c6 to your computer and use it in GitHub Desktop.
Save compustar/14508196a1486b2548d41e55e54af8c6 to your computer and use it in GitHub Desktop.
VBA to merge Excel Worksheets
Sub Macro3()
'
' Macro3 Macro
'
newSheetName = "MergedSheet"
On Error Resume Next
Sheets(newSheetName).Select
If ActiveSheet.Name <> newSheetName Then
Sheets.Add
ActiveSheet.Name = newSheetName
End If
For Each x In Sheets
If x.Name <> newSheetName Then
x.Select
Range("A1").CurrentRegion.Select
Selection.Copy
Range("A1").Select
Sheets(newSheetName).Select
ActiveSheet.Paste
Cells(Cells(1, 2).End(xlDown).Row + 1, 1).Select
End If
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment