Splitting a string with variable number of spaces VBA
Posted
by GVBA
on Stack Overflow
See other posts from Stack Overflow
or by GVBA
Published on 2010-01-30T14:34:06Z
Indexed on
2010/04/21
11:03 UTC
Read the original article
Hit count: 227
excel-vba
I have a file with a bunch of number in columns. These numbers are separated by variable number of spaces. I want to skip the first line and get all the other lines and separte each number on the line. Finally, I want to write each number on Excel. I've been able to get the lines and write them on Excel but I can't separate each number (I'm getting the whole line as one string).
Does any body know how to split a string that has a variable number of spaces?
Here is my code.
Sub Test()
r = 0
With New Scripting.FileSystemObject
With .OpenTextFile("C:\Users\User\Desktop\File.tab", ForReading)
If Not .AtEndOfStream Then .SkipLine
Do Until .AtEndOfStream
ActiveCell.Offset(r, 0) = Split(.ReadLine, vbCrLf)
r = r + 1
Loop
End With
End With
End Sub
© Stack Overflow or respective owner