View Single Post
  #7   Report Post  
Old August 13th 19, 10:08 AM posted to microsoft.public.excel.programming
RG III RG III is offline
external usenet poster
 
First recorded activity by ExcelBanter: May 2019
Posts: 64
Default Why the heck doesn't this work?

Hi Garry!

I finally got around to testing your code. It pretty much
does what I wanted, but I had to tweak it slightly because the
second or third Split function call was leaving a line feed in the
beginning of some strings. But, I'm happy with the results, so
thank you very much!

Robert

On Tuesday, June 4, 2019 at 1:54:31 AM UTC-7, GS wrote:
Finally...

Sub ParseTextFile2b()
' Parses a multi-line text file
Dim vText, vTmp, n&, k&
Const sFile$ = "C:\Data.txt"
'//where the file contains
'a123 A. BC #123
'b123 B. CD #123
'c123 C. DE #123

'Get the file contents and parse each line
vText = Split(ReadTextFile(sFile), vbCrLf)

'Parse each line in the file
For k = LBound(vText) To UBound(vText)
'Get the line text parsed by 'TAB' characters
vTmp = Split(vText(k), vbTab)
For n = LBound(vTmp) To UBound(vTmp)
Debug.Print vTmp(n)
Next 'n

'Parse the 2nd element by 'SPACE' characters
vTmp = Split(vTmp(1), " ")
For n = LBound(vTmp) To UBound(vTmp)
Debug.Print vTmp(n)
Next 'n
Next 'k
End Sub

..which returns the following:
a123
A. BC #123
A.
BC
#123
b123
B. CD #123
B.
CD
#123
c123
C. DE #123
C.
DE
#123