Writing the content of multiple csv files to an excel sheet
Hello all,
my question will probably sound simple, as I have just started learning programming with VBA.
I am trying to use the content of multiple csv files and write it all in an excel spreasheet. All my csv files are the same, and I want to get the content (for example) of column 2,3,4 and 10 from line 27 to the end of file (which is on line 390) for each file. I want the content of each file written side by side in my excel sheet.
So far I have tried to work with some lines of codes that are not really working (this example is not really adapted to my end goal described above, it is just a first step):
Sub OpenTextFile()
Dim FilePath As String
FilePath = "C:\Users\myfile.csv"
Open FilePath For Input As #1
row_number = 1
Do Until EOF(1)
LineFromFile = 27
Line Input #1, LineFromFile
LineItems = Split(LineFromFile, ",")
ActiveCell.Offset(row_number, 0).Value = LineItems(2)
ActiveCell.Offset(row_number, 1).Value = LineItems(3)
ActiveCell.Offset(row_number, 2).Value = LineItems(4)
ActiveCell.Offset(row_number, 3).Value = LineItems(10)
row_number = row_number + 1
Loop
Close #1
End Sub
Thank you if anyone has an idea.
Recent comments
5 years 34 weeks ago
6 years 20 weeks ago
6 years 32 weeks ago
6 years 35 weeks ago
6 years 36 weeks ago
6 years 42 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago