Option Explicit
Sub GetCSVData()
Dim SelectFolder As Integer
Dim x As Long, rowLast As Long
Dim strPath As String
Dim FirstFile As Boolean
Dim wbSummary As Workbook, wb As Workbook
Dim wsSummary As Worksheet, ws As Worksheet
Dim FSO As Object
Dim FSOLibrary As Object
Dim FSOFolder As Object
Dim sFileName As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set wbSummary = ActiveWorkbook
Set wsSummary = wbSummary.Sheets("Sheet1")
SelectFolder = Application.FileDialog(msoFileDialogFolderPicker).Show
If Not SelectFolder = 0 Then
strPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
Else
End
End If
Application.ScreenUpdating = False
'Set all the references to the FSO Library
Set FSOLibrary = CreateObject("Scripting.FileSystemObject")
Set FSOFolder = FSOLibrary.GetFolder(strPath)
x = 2
FirstFile = True
'Loop through each file in a folder
For Each sFileName In FSOFolder.Files
Set wb = Workbooks.Open(sFileName)
Set ws = wb.Sheets(1)
rowLast = ws.Range("B" & ws.Rows.Count).End(xlUp).Row
If FirstFile Then
ws.Range("A1", "B" & rowLast).Copy wsSummary.Range("A2")
FirstFile = False
Else
x = x + 1
ws.Range("B1", "B" & rowLast).Copy wsSummary.Cells(2, x)
End If
wsSummary.Cells(1, x) = Dir(sFileName)
wb.Close True
Next
Set FSOLibrary = Nothing
Set FSOFolder = Nothing
Application.ScreenUpdating = True
End Sub