import huge text file line-by-line?

G

Guest

I'm trying to automate importing an enormous text file. The full file has
over 1000 fields (don't ask... it's just what I have to deal with). I want to
bring in around 150 or so of the fields. I recorded a macro using the text
import wizard. There were too many line continuations, so I tried to condense
the code into fewer lines. Because of the number of fields, however, there's
still way too much code and not enough allowable line continuations.

I've read suggestions for importing the text line by line and truncating
just what I want, but i'm not sure how to do it. The text file is delimited
with a ~ character. The first field has names formatted as "last, first" (no
quotes, but there is a comma). Because the first field is a name, the length
of that field will vary by person, as will the length of some of the other
fields. I don't know how to write the code that will snip out just those
fields i want while taking into account the varying length of some of the
fields.

Any help would be appreciated.
rachael
 
M

mangesh_yadav

did you try the split function. You can use something like
fields = Split(line_number, "~")
This will put the fields in the array fields, and then you can impor
only those numbers which you want by referring to them as field(0)
field(4), field(21), etc...

- Manges
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top