I want to code a macro that searches through multiple .xls* files and copies the tables into one big table in my masterfile. Currently the macro is able to access the different files and can copy the information. Now I want it to paste it into one table in my masterfile but i dont know how to make it paste the information from one table at the end of another without knowing how big each table is, so there is no overlapping or empty lines.
Sub New_Data()
Dim wb As Workbook
Dim ws As Worksheet
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
'Deletes all current data in the masterfile
Application.DisplayAlerts = False
For Each ws In Worksheets
If ws.Name = "Overview" Then ws.Range(A2, AT10000).ClearContents
Application.DisplayAlerts = True
'User can pick what folder he wants to get his data from
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Please pick a Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
'If invalid path is put in
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
'All data ending on .xls* gets picked
myExtension = "*.xls*"
'Declares the files as combination of path and .xsl*
myFile = Dir(myPath & myExtension)
'Loop that actually opens up the files and picks the data from it
Do While myFile <> ""
Set wb = Workbooks.Open(Filename:=myPath & myFile)
DoEvents
'Actual Process of copying, as you can see im totally lost
For Each ws In Worksheets
If ws.Name = "Übersicht" Then ws.Range("B6:BT10000").Copy
Before ThisSheet.Range("A2:AT64").Paste
wb.Close SaveChanges:=False
DoEvents
myFile = Dir
Loop
'Feedback, for the code is done
MsgBox "Done!"
End Sub
The problem is that I need to copy a varying amount of cells and have absolutly no clue how to achive that, any help (preferably explained simple, I'm quite new to VBA) will be appreciated, thanks a lot in advance.