View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Dave O Dave O is offline
external usenet poster
 
Posts: 427
Default one VERY LONG line

This code will take that enormous string and parse it into 5 fields per
row. It's not pretty but will do the job. It works by counting commas
and parsing the data into a new file, which you can then import. It
will not change the original file in any way. Note for the lines in
the code that start with "Open" you'll need to specify your path and
file name.


Sub Parse_File()
Dim Lyne As String
Dim FoundComma As Byte
Dim K As Long, Z As Long, Start As Long, LastStart
Start = 1

Open "c:\ok2del.txt" For Input As #1
Open "c:\import.txt" For Output As #2

Do While Not EOF(1)
Line Input #1, Lyne
Lyne = Trim(Lyne)
If Right(Lyne, 1) < "," Then Lyne = Lyne & ","
'begin a parsing loop
Z = 0
Do
Z = Z + 1
K = K + 1
If Mid(Lyne, Z, 1) = "," Then FoundComma = FoundComma + 1
If FoundComma = 5 Then
Print #2, Mid(Lyne, Start, K)
MsgBox Start & " " & K
LastStart = LastStart + K
Start = LastStart + 1
FoundComma = 0
K = 0
End If
Loop Until Z = Len(Lyne)
Loop
Close #1
Close #2

End Sub