This is sort of a "which direction is best" sort of question. I have a .CSV file that is in a less then ideal format. I'll diagram the file below so you can see what I'm talking about. This file is provided to me by a vendor who should know better... (Google, cough, hack, cough).
What is the best way to import only table2 from this data using VBA? I'll list methods I've been trying after the diagram.
.CSV file looks like this if opened:
Title Cell
File Info Cell
Time Date Cell
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
Data1, Data 2
....(continues for around 800 rows)
Second Table Title Cell
Col1Title, Col2Title, ColTitle, Col4Title ....(continues for around 50 columns)
Data 3, Data4, Data 5, Data6 ....(continues for around 50 columns)
Data 3, Data4, Data 5, Data6 ....(continues for around 50 columns)
Data 3, Data4, Data 5, Data6 ....(continues for around 50 columns)
Data 3, Data4, Data 5, Data6 ....(continues for around 50 columns)
Data 3, Data4, Data 5, Data6 ....(continues for around 50 columns)
Data 3, Data4, Data 5, Data6 ....(continues for around 50 columns)
Data 3, Data4, Data 5, Data6 ....(continues for around 50 columns)
Data 3, Data4, Data 5, Data6 ....(continues for around 50 columns)
...(Continues for around 1500 rows)
End of CSV
I've thus far attempted to the ADODB object but that relies on SQL query's (which to my limited SQL knowledge) assume that the data is formated correctly as a table - which it is not here.
I've also been trying reading the file line by line.
I could force either of these two solutions to work, but it's pretty messy both ways. I feel like there has to be clean way to do this?
Can anyone suggest a better approach or an efficient approach to the methods I've already tried?
Thanks in advance.
addendum
@ user3724 this is what i've been trying on the line by line approach:
Open strFile For Input As #1
countLine = 0
Do Until EOF(1)
Line Input #1, LineFromFile
(Increment countLine)
(Break line into array)
(strComp() each element with the value for title of Table 2)
(When strComp() returns true return countLine as upperValue)
(Exit Loop)
Loop
countLine = 0
Do Until EOF(1)
Line Input #1, LineFromFile
(Increment countLine)
If countline is >= uppervalue
(Parse line and return it to target row of target worksheet)
End If
Loop
When I code this whole thing out it is a slow mess - lots of if statements and loops within loops. @user3724, could you review this based on your experience?