View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.newusers
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default vba code for excel to extract data from txt file

JE,
Is your sample report example shown here exactly like the real deal? Each
record has 4 rows:
1st row starts with Ref #:
2nd row starts with TD:
3rd row starts with SD:
4th row starts with MKT:

and there is no additional information on each row other than what you've
shown here? What about the rest of the report - are there blank lines or
such between the 4-row records, although my method doesn't really care, still
nice to know.

I perform similar parsing on variable sized fields in a text file output by
an accounting system for personnel records. I have an array that holds the
text that defines a field, such as REF #: and CUSIP: and it uses that
information to pick up the data within the fields in the records.

If what you've shown is accurate, we can put together something fairly
quickly.

"JE" wrote:

USING Excel 2000.
I have a text file that when viewed in excel lists the entire row of data in
one cell. I cannot parse data because each line does not have the same
break. I want to extract the fields into individual cells. I will need to
define "what" I am looking for. Is there sample vba code for excel I can
reference to learn how this may be done?

sample report

REF #:A1B CUSIP:12345678
TD:1/1/00 SYMBOL:ABC QTY: 1
SD:01/03/00 ACME COMPANY PRICE: 9.101
MKT:OTC


want to extract

REF# TD SD CUSIP MKT SYMBOL FIELD1 QTY
PRICE PRICE
A1B 1/1/00 1/3/00 12345678 OTC ABC ACME COMPANY 1
9.101