Merge Multiple Files into One Worksheet

mandeep911

New Member
Joined
May 5, 2016
Messages
1
Hello,

I am trying to merge multiple files into one workbook. The files are saved in one folder but have multiple sheet in them. I would like to copy data from only one sheet (""DAILY_DETAIL") and combine to one sheet.

I am trying to use the below macro but for some reason it is copying A1:AS to A2:AS. Not sure why this is happening I was able to use this code with files that had only one sheet.

Any Idea?


Sub simpleXlsMerger()
Dim bookList As Workbook
Dim bookSheet As Worksheet
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Application.EnableEvents = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")

Set dirObj = mergeObj.Getfolder("N:\AOC\Access and Support\Access\Reports\2016")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)

Set bookSheet = bookList.Sheets("DAILY_DETAIL")
bookSheet.Range("A2:AS" & Range("A1048576").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate

Range("A1048576").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
bookList.Close
Next
Application.ScreenUpdating = True
Application.EnableEvents = False
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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