katiapro93
Board Regular
- Joined
- Jun 25, 2009
- Messages
- 140
I have worked with Macros, but I am in no way a pro and I need some help getting started. I need to get a bunch of excel workbooks saved in one directory into one workbook. Every day, I will have new reports in a directory that I need to combine into one. Ideally, I would like to clear the one workbook that has the merge data and replace it with a merge of the reports in the directory.
I came across this code, but right off the bat it gives me an error saying it can't find an object. Can some one help me to create a code to clear my master merge workbook and replace it with a new merge of all the data from differed workbooks saved in a directory?
Here is what I have so far.
Sub simpleXlsMerger()
Dim booklist As Workbook
Dim MergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set MergeObj = CreateObject("Scripting.FileSystemObject")
'change folder path of excel files here
Set dirObj = MergeObj.getfolder("C:\change\to\excel\files\path\here")
Set filesObj = dirObj.Files
For Each everyObj In fileObj
Set booklist = Workbooks.Open(everyObj)
'change "A2" with cell reference of start point for every file here
'for example "B3:Iv" to merge all files start from column B and Row 3
'If you're files are using more than IV column, change it to the last column
'Also change "A" column on "A65536" to the same column as start point
Range("A2:IV" & Range("A65536").End(x1Up).Row).Copy
ThisWorkbook.Worksheets(1).Activate
'Do not change the following column. It's not the same column as above
Range("A65536").End(x1Up).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
booklist.Close
Next
End Sub
I came across this code, but right off the bat it gives me an error saying it can't find an object. Can some one help me to create a code to clear my master merge workbook and replace it with a new merge of all the data from differed workbooks saved in a directory?
Here is what I have so far.
Sub simpleXlsMerger()
Dim booklist As Workbook
Dim MergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set MergeObj = CreateObject("Scripting.FileSystemObject")
'change folder path of excel files here
Set dirObj = MergeObj.getfolder("C:\change\to\excel\files\path\here")
Set filesObj = dirObj.Files
For Each everyObj In fileObj
Set booklist = Workbooks.Open(everyObj)
'change "A2" with cell reference of start point for every file here
'for example "B3:Iv" to merge all files start from column B and Row 3
'If you're files are using more than IV column, change it to the last column
'Also change "A" column on "A65536" to the same column as start point
Range("A2:IV" & Range("A65536").End(x1Up).Row).Copy
ThisWorkbook.Worksheets(1).Activate
'Do not change the following column. It's not the same column as above
Range("A65536").End(x1Up).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
booklist.Close
Next
End Sub