I have a need to open up all the .xlsx files in a folder and copy their contents into the workbook that is running the macro. I have gotten so far as being able to loop through all the Excel files in a folder thanks to this blog post, with one change in the code from myExtension = "*.xls"
to myExtension = "*.xlsx"
. However I can't figure out how to copy all the contents of worksheet 1 of each workbook and paste it into ThisWorkbook
which is the one running the macro.
For instance, in the Do While
loop, the code in the blog post above does this:
'Change First Worksheet's Background Fill Blue
wb.Worksheets(1).Range("A1:Z1").Interior.Color = RGB(51, 98, 174)
But I want to do something like this:
'Copy all the cells that have data in them and paste/append to VBA workbook
wb.Worksheets(1).UsedRange.Copy ' this hasn't been working for me
ThisWorkbook.Worksheets(1). (somehow get to the first empty row) . Paste
Any ideas?
By the way, the Excel files that I'm copying from will all have their data in the first sheet and they will not have any header rows.