Split(linefromfile, " ") when it is a txt file with spaces deliminating

MetLife

Active Member
Joined
Jul 2, 2012
Messages
283
Hi,

I am trying to read in from a txt file. The columns are spaced using various lengths of spaces " ". So I can't just use a single space in the code. Does anyone know a way around this?

'Step #1 - find the table #2
For i = 0 To 1500
If EOF(1) Then GoTo L2
Line Input #1, linefromfile
lineitems = Split(linefromfile, " ")
If i < 2 Then
'SKIP HEADERS
Else
'If lineitems(0) = iiage Then
For j = 1 To 15
out(i, j) = lineitems(j - 1)
Next j
'End If
End If
Next i
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
change
VBA Code:
Line Input #1, linefromfile
lineitems = Split(linefromfile, " ")
to
VBA Code:
Line Input #1, linefromfile
Do
    linefromfile_prev = linefromfile
    linefromfile = Replace(linefromfile, Space(2), Space(1))
    If linefromfile_prev = linefromfile Then
        Exit Do
    End If
Loop
lineitems = Split(linefromfile, " ")
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,387
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top