Fetch data from multiple .csv file paste into single sheet
Hi Deen,
Hope I have interpreted your request properly.
Copy the following code into a standard module. (See below for more
instructions)
Sub OpenTxtFile(strPath As String)
Dim myTitle As String 'Dalog box title
Dim sFile As String 'Path and csv file name
Dim wbTxt As Workbook
myTitle = "Select the required text file"
With Application.FileDialog(msoFileDialogFilePicker)
.Title = myTitle
.Filters.Clear
.AllowMultiSelect = False
.InitialFileName = strPath
.Filters.Add "Text files", "*.csv", 1
If .Show = False Then
Exit Sub 'If user cancels in dialog box
End If
sFile = .SelectedItems(1)
End With
Workbooks.OpenText Filename:=sFile
Set wbTxt = ActiveWorkbook
wbTxt.Sheets(1).UsedRange.Copy _
Destination:=ThisWorkbook.Sheets("Inventory") _
.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
wbTxt.Close
End Sub
Now assuming that you have the file paths in your text boxes, you can call
this code from each of your browse buttons like the following example for the
first button. This calls the sub in the standard module and passes the value
(path) in the textbox to the Sub OpenTxtFile.
Private Sub CommandButton1_Click()
Call OpenTxtFile(Me.TextBox1.Value)
End Sub
The contents of the csv file is copied to Inventory as each csv file is
opened and then the csv file is closed again.
--
Regards,
OssieMac
|