Created
May 1, 2017 11:02
-
-
Save caglarorhan/92887abf446adc0a0491cb793edf2618 to your computer and use it in GitHub Desktop.
Merge Multiple Same Structered Excel Files Into One Files Worksheets - This is a VBA Sub Routine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub simpleXlsMerger() | |
Dim bookList As Workbook | |
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object | |
Dim lastRow | |
Application.ScreenUpdating = False | |
Set mergeObj = CreateObject("Scripting.FileSystemObject") | |
'Main folder which includes just excel files | |
Set dirObj = mergeObj.Getfolder("C:\main") | |
Set filesObj = dirObj.Files | |
For Each everyObj In filesObj | |
Set bookList = Workbooks.Open(everyObj) | |
'// | |
bookList.Worksheets(1).Activate | |
lastRow = bookList.Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row | |
Range("A2:G" & lastRow).Copy '// if A2 is first leftupper cell and G is the las column | |
ThisWorkbook.Worksheets(1).Activate | |
Range("A" & Range("A" & Rows.Count).End(xlUp).Row & ":G" & Range("A" & Rows.Count).End(xlUp).Row).PasteSpecial | |
Application.CutCopyMode = False | |
bookList.Close | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment