Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default multi-line text file import to excel

I need some guidance on how to handle a multi-line text file import to
excel.

I have a multi-line text file i am attempting to parse into Excel2003.
Here is an example of the file:


<rlnrp:cell=all;
NEIGHBOUR RELATION DATA


CELL
WA32300


CELLR DIR CAND CS
WA31340 MUTUAL BOTH NO


KHYST KOFFSETP KOFFSETN LHYST LOFFSETP LOFFSETN
3 0 3 0


TRHYST TROFFSETP TROFFSETN AWOFFSET BQOFFSET
2 0 5 3


HIHYST LOHYST OFFSETP OFFSETN BQOFFSETAFR
5 3 0 3


CELLR DIR CAND CS
WA30780 MUTUAL BOTH NO


KHYST KOFFSETP KOFFSETN LHYST LOFFSETP LOFFSETN
3 0 3 0


TRHYST TROFFSETP TROFFSETN AWOFFSET BQOFFSET
2 0 5 3


HIHYST LOHYST OFFSETP OFFSETN BQOFFSETAFR
5 3 0 3


CELL
WA30433


CELLR DIR CAND CS
WA31960 MUTUAL BOTH NO


KHYST KOFFSETP KOFFSETN LHYST LOFFSETP LOFFSETN
3 0 3 0


TRHYST TROFFSETP TROFFSETN AWOFFSET BQOFFSET
2 0 5 3


HIHYST LOHYST OFFSETP OFFSETN BQOFFSETAFR
5 3 0 3


END


---------------------------------------------------------------
Details of where i am trying to go with this:


The format of the source file is not modifiable so i am left to deal
with it as is. I had created a macro to handle the basic import a space

delimited and then another macro to sort it the way i wanted. This
worked until the text file exceeded 65000 lines in excel. Now it has
become an issue. What i ultimately need to achieve is a way to define a

Start and Stop where all data between Start and Stop is read in as 1
line. It would identify CELL as the Start and read in to 1 line until
it comes across CELL (Stop) again. Then continues on. I just need the
CELL and CELLR data. Thus looking like so:


CELL CELLR
WA32300 WA31340 WA30780
WA30433 WA31960


......and so on down the file.


So, either some sort of Start and Stop trigger to define when to start
writing a new line into Excel or a means of sending a string to a
specific range (column) within Excel. So, any help or guidance you can
offer will be much appreciated.


Thank you

  #2   Report Post  
Posted to microsoft.public.excel.programming
ADG ADG is offline
external usenet poster
 
Posts: 76
Default multi-line text file import to excel

I would use VBA to read the text file and populate Excel. I think the below
should give you an idea where to start. The below code reads the text file
and puts the references into a new book. Where I have hard coded the file
name you should link this to a cell value. The code runs from a button put
into an empty sheet


Private Sub CommandButton1_Click()
Dim Fn, r, c As Long
Dim LineOfText As String
Dim xlBook As Excel.Workbook

r = 1
c = 1
Set xlBook = Application.Workbooks.Add

Fn = FreeFile()
Open "c:\cell.txt" For Input As Fn
While Not EOF(Fn)
Line Input #Fn, LineOfText

If Left$(LineOfText, 5) = "CELLR" Then
c = c + 1
Line Input #Fn, LineOfText
ActiveSheet.Cells(r, c).Value = Left$(LineOfText, 7)
ElseIf Left$(LineOfText, 4) = "CELL" Then
r = r + 1
c = 1
Line Input #Fn, LineOfText
ActiveSheet.Cells(r, c).Value = Left$(LineOfText, 7)
End If
Wend

Close #Fn
End Sub
--
Tony Green


"Waxaholic" wrote:

I need some guidance on how to handle a multi-line text file import to
excel.

I have a multi-line text file i am attempting to parse into Excel2003.
Here is an example of the file:


<rlnrp:cell=all;
NEIGHBOUR RELATION DATA


CELL
WA32300


CELLR DIR CAND CS
WA31340 MUTUAL BOTH NO


KHYST KOFFSETP KOFFSETN LHYST LOFFSETP LOFFSETN
3 0 3 0


TRHYST TROFFSETP TROFFSETN AWOFFSET BQOFFSET
2 0 5 3


HIHYST LOHYST OFFSETP OFFSETN BQOFFSETAFR
5 3 0 3


CELLR DIR CAND CS
WA30780 MUTUAL BOTH NO


KHYST KOFFSETP KOFFSETN LHYST LOFFSETP LOFFSETN
3 0 3 0


TRHYST TROFFSETP TROFFSETN AWOFFSET BQOFFSET
2 0 5 3


HIHYST LOHYST OFFSETP OFFSETN BQOFFSETAFR
5 3 0 3


CELL
WA30433


CELLR DIR CAND CS
WA31960 MUTUAL BOTH NO


KHYST KOFFSETP KOFFSETN LHYST LOFFSETP LOFFSETN
3 0 3 0


TRHYST TROFFSETP TROFFSETN AWOFFSET BQOFFSET
2 0 5 3


HIHYST LOHYST OFFSETP OFFSETN BQOFFSETAFR
5 3 0 3


END


---------------------------------------------------------------
Details of where i am trying to go with this:


The format of the source file is not modifiable so i am left to deal
with it as is. I had created a macro to handle the basic import a space

delimited and then another macro to sort it the way i wanted. This
worked until the text file exceeded 65000 lines in excel. Now it has
become an issue. What i ultimately need to achieve is a way to define a

Start and Stop where all data between Start and Stop is read in as 1
line. It would identify CELL as the Start and read in to 1 line until
it comes across CELL (Stop) again. Then continues on. I just need the
CELL and CELLR data. Thus looking like so:


CELL CELLR
WA32300 WA31340 WA30780
WA30433 WA31960


......and so on down the file.


So, either some sort of Start and Stop trigger to define when to start
writing a new line into Excel or a means of sending a string to a
specific range (column) within Excel. So, any help or guidance you can
offer will be much appreciated.


Thank you


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default multi-line text file import to excel

Awesome. Thank you very much. This will certainly save me some time.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Line text box jmonesmith Excel Discussion (Misc queries) 3 September 6th 07 09:06 PM
Text File Import leaves a blank row after each line R Kapoor Setting up and Configuration of Excel 0 January 8th 06 02:07 PM
Saving multi-tab excel file created from comma delimited text file Marcus Aurelius Excel Programming 2 December 19th 05 05:16 PM
copy/paste excel to texteditor -> multi-line text cells gain unwanted double-quotes niz Excel Discussion (Misc queries) 1 October 14th 05 02:06 PM
import huge text file line-by-line? rachel Excel Programming 2 November 6th 04 04:43 PM


All times are GMT +1. The time now is 10:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"