A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Using the following code will do what you want:
Sub DataPull()
Dim foldername As String
Dim Source As Workbook
Dim Target As Workbook
Dim counter As Long
Dim strFile As String
Dim fd As FileDialog
Dim i As Long, m As Long, n As Long
Set Target = ActiveWorkbook
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Select the folder that contains the files that you want to import."
If .Show = -1 Then
strFolder = .SelectedItems(1) & ""
Else
MsgBox "You did not select a folder."
Exit Sub
End If
End With
strFile = Dir$(strFolder & "*.xlsx")
counter = 0
While strFile <> ""
Set Source = Workbooks.Open(strFolder & strFile)
With Target.Sheets(1).Range("A1")
i = .CurrentRegion.Rows.Count
For m = 1 To Source.Sheets(1).Range("A1").CurrentRegion.Rows.Count - 1
For n = 0 To Source.Sheets(1).Range("A1").CurrentRegion.Columns.Count - 1
.Offset(i, n) = Source.Sheets(1).Range("A1").Offset(m, n)
Next n
i = i + 1
Next m
End With
counter = counter + 1
Source.Close xlDoNotSaveChanges
strFile = Dir$()
Wend
MsgBox ("Finished and processed " & counter & " files") 'This displayes a message box inc. the value of Counter
End Sub