Ive tried searching and using different methods and cannot figure this out. About 2-3 times a week I have about 25-100 different text files that I periodically need to import data from to my spreadsheet. The name of the text file will change each day but I am able to paste the titles in row 1 on my spreadsheet. Also, all of the text files are saved to their own folder each time and are not comingled with any other text files if that makes it easier.
Ive attached a spreadsheet with the layout I am using and a sample the text file I am importing data from.
So is your ask here, to import the data from each text file regardless of folder/location into your spreadsheet?
If so, do you already have the looping logic to handle looking for each file?
If all you want to do is merely copy/import the data from the text file into your sheet, this is one method you can try
, inside your loop call the logic below for each file you process.
According to the attachment to import a column the classic method VBA demonstration as a beginner starter :
PHP Code:
Sub Demo1()
V = Application.GetOpenFilename("Text Files,*.txt")
If V = False Then Exit Sub
With [A1].CurrentRegion.Columns
W = .Item(1).Value2
W(1, 1) = Split(V, "\"): W(1, 1) = W(1, 1)(UBound(W(1, 1)))
F% = FreeFile
Open V For Input As #F
Line Input #F, W(2, 1): Line Input #F, W(2, 1)
For R& = 2 To UBound(W)
Line Input #F, W(R, 1)
W(R, 1) = Split(W(R, 1), vbTab)(3)
Next
Close #F
With .Item(Cells(2, Columns.Count).End(xlToLeft).Column + 1): .Value2 = W: .AutoFit: End With
End With
End Sub
► Do you like it ? ► ► So thanks to click on bottom left star icon « ★ Add Reputation » ! ◄ ◄
Bookmarks