View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default Controlling Text Loading

You can certainly load this via ODBC using the Microsoft Text Driver
It wouldn't solve your problem of wrapping after 50,000 records.

As Tom suggests, you may want to put the data into Access first before
moving to Excel.



--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Nigel" wrote in message
...
Rob,
Thanks very much. I'll try this, but you have got me thinking about ODBC.
I do not know enough about this other than I can connect to the file

without
loading it into Excel. But do you know if I can search the Text file and
extract the relevant bits into Excel?

Cheers
Nigel

"Rob van Gelder" wrote in message
...
Nigel,

I didn't properly test the tab positions. There might be some issues

from
0-based to 1-based offsets, but I think you should be able to work with
this.
It gets really slow for 150,000 records. My test file was about 7MB.

Maybe
another, faster, solution will be posted soon?
Might even be opportunity for using ODBC against flatfile.

Sub test()
Const cCol1 = 20, cCol2 = 20, cCol3 = 20, cLimit = 50000
Dim intFreeFile As Integer, i As Long, j As Long, strTemp As String

'Generate a test file
intFreeFile = FreeFile
Open "c:\t\test.txt" For Output As #intFreeFile
For i = 1 To 150
Print #intFreeFile, "R" & i & "C1"; Tab(cCol1 + 1); "R" & i &

"C2";
Tab(cCol1 + cCol2 + 1); "R" & i & "C3"
Next
Close #intFreeFile

'Load test file into Cells
intFreeFile = FreeFile
Open "c:\t\test.txt" For Input As #intFreeFile
i = 1: j = 1
Do Until EOF(intFreeFile)
Line Input #intFreeFile, strTemp
Cells(i, j).Value = Trim(Mid(strTemp, 1, cCol1))
Cells(i, j + 1).Value = Trim(Mid(strTemp, cCol1, cCol2))
Cells(i, j + 2).Value = Trim(Mid(strTemp, cCol1 + cCol2, cCol3))
i = i + 1
If i cLimit Then
i = 1
j = j + 3
End If
Loop
Close #intFreeFile
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Nigel" wrote in message
...
Sorry, the target references should have been A:C; D:F, G:I etc., No

wonder
I need help!!

"Nigel" wrote in message
...
Hi All
I have a fixed width text file which contains three columns of data

and
up
to 150,000 rows

I wish to read these into a worksheet, parsing the text into three

columns
(by specifying each column width), putting the data into columns A:C

until
I
reach 50,000. Then loading the next 50,000 rows into columns C:E,

the
next
F:H etc., until all rows have been loaded.

Any help greatly appreciated.

Cheers
Nigel




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet
News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World!

100,000
Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via

Encryption
=---




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet

News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World!

100,000
Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via

Encryption
=---






----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet

News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000

Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---