Ricardo Caicedo
New Member
- Joined
- Aug 21, 2014
- Messages
- 43
Hello Guys</SPAN>
I need to import several CSV files to specific fields in my sheet.</SPAN>
So far with the code is a working well, but just if the imported files have the same number of fields by rows (or columns).However the CSV files can change as sometimes has 6 columns sometimes just 3.</SPAN>
I feed the data in a variable name x, that contains the import fields.</SPAN>
If the files are different I got the error subscript 9 as the x variable got short and creates the fail.</SPAN>
See so far</SPAN>
Dim fName, x</SPAN></SPAN>
Open fName For Input As #1</SPAN></SPAN>
Do Until EOF(1)</SPAN></SPAN>
Line Input #1, Data</SPAN></SPAN>
x = Split(Data, ",")</SPAN></SPAN>
Cells(NextRow, "N").Value = x(2) 'Extract Daily </SPAN></SPAN>
Cells(NextRow, "O").Value = x(3) 'Extract Monthly </SPAN></SPAN>
Cells(NextRow, "J").Value = x(4) 'Extract Fi</SPAN></SPAN>
Cells(NextRow, "P").Value = x(5) 'Extract Bal </SPAN></SPAN>
Cells(NextRow, "Q").Value = x(6) 'Extract 5%</SPAN></SPAN>
Cells(NextRow, "R").Value = x(7) 'Extract 5%</SPAN></SPAN>
NextRow = NextRow + 1</SPAN></SPAN>
Loop</SPAN></SPAN>
Close #1</SPAN></SPAN>
How I can control x or knew the number of columns so I can fix the code?</SPAN></SPAN>
Thank you Guys very appreciate</SPAN></SPAN>
I need to import several CSV files to specific fields in my sheet.</SPAN>
So far with the code is a working well, but just if the imported files have the same number of fields by rows (or columns).However the CSV files can change as sometimes has 6 columns sometimes just 3.</SPAN>
I feed the data in a variable name x, that contains the import fields.</SPAN>
If the files are different I got the error subscript 9 as the x variable got short and creates the fail.</SPAN>
See so far</SPAN>
Dim fName, x</SPAN></SPAN>
Open fName For Input As #1</SPAN></SPAN>
Do Until EOF(1)</SPAN></SPAN>
Line Input #1, Data</SPAN></SPAN>
x = Split(Data, ",")</SPAN></SPAN>
Cells(NextRow, "N").Value = x(2) 'Extract Daily </SPAN></SPAN>
Cells(NextRow, "O").Value = x(3) 'Extract Monthly </SPAN></SPAN>
Cells(NextRow, "J").Value = x(4) 'Extract Fi</SPAN></SPAN>
Cells(NextRow, "P").Value = x(5) 'Extract Bal </SPAN></SPAN>
Cells(NextRow, "Q").Value = x(6) 'Extract 5%</SPAN></SPAN>
Cells(NextRow, "R").Value = x(7) 'Extract 5%</SPAN></SPAN>
NextRow = NextRow + 1</SPAN></SPAN>
Loop</SPAN></SPAN>
Close #1</SPAN></SPAN>
How I can control x or knew the number of columns so I can fix the code?</SPAN></SPAN>
Thank you Guys very appreciate</SPAN></SPAN>