ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Parse Text File (https://www.excelbanter.com/excel-programming/279682-parse-text-file.html)

John[_62_]

Parse Text File
 
I have a text file with almost 60,000 rows of data
seperated into many different sections. The rows in each
section have a different number of fields and field
lenghts. Right now, I'm only interested in pulling data
from one section. I'd like to write a macro to go line by
line until it finds the title of the section I'm
interested in, start reading and parsing the data, then
stop when it finds the name of a new section. I know how
to read an entire text file and parse data. How can I
make the macro start when it finds the begining of a
section and stop at the end of the section?

Thanks for any help.

michael bond

Parse Text File
 
John

don't know your exact data but something like this may
work:

Dim Datarow as Long

Datarow = 1

....'(assumes first line of data is first row of worksheet)

Do until cells(Datarow, 1) = "whatever"
Datarow = Datarow + 1
Loop
Cells(Datarow, 1).select

.....'this gets you to the start point of your section
(I've assumed your section has a name which you use in
place of "whatever"

Do until cells(Datarow, 1) = "whatever section end is"

......your code here to work on your data

Datarow = Datarow + 1
Loop

There are probably other ways but I've used this method
successfuly for similar worrk to that which you describe.

HTH

Michael Bond

-----Original Message-----
I have a text file with almost 60,000 rows of data
seperated into many different sections. The rows in each
section have a different number of fields and field
lenghts. Right now, I'm only interested in pulling data
from one section. I'd like to write a macro to go line

by
line until it finds the title of the section I'm
interested in, start reading and parsing the data, then
stop when it finds the name of a new section. I know how
to read an entire text file and parse data. How can I
make the macro start when it finds the begining of a
section and stop at the end of the section?

Thanks for any help.
.


michael bond

Parse Text File
 
John

just an afterthought...with such a lot of data its worth
adding

Application.DisplayAlerts = False...at begining of code

and

Application.DisplayAlerts = True...at end

This will avoid screen refresh for each line of file you
work on and will speed up the running of your project

Michael

-----Original Message-----
I have a text file with almost 60,000 rows of data
seperated into many different sections. The rows in each
section have a different number of fields and field
lenghts. Right now, I'm only interested in pulling data
from one section. I'd like to write a macro to go line

by
line until it finds the title of the section I'm
interested in, start reading and parsing the data, then
stop when it finds the name of a new section. I know how
to read an entire text file and parse data. How can I
make the macro start when it finds the begining of a
section and stop at the end of the section?

Thanks for any help.
.


John[_62_]

Parse Text File
 
Thanks for the response Michael, but will this work on a
text file? I'm trying to read the text file directly
using VBA. I don't want to import it first.

John

-----Original Message-----
John

don't know your exact data but something like this may
work:

Dim Datarow as Long

Datarow = 1

....'(assumes first line of data is first row of

worksheet)

Do until cells(Datarow, 1) = "whatever"
Datarow = Datarow + 1
Loop
Cells(Datarow, 1).select

.....'this gets you to the start point of your section
(I've assumed your section has a name which you use in
place of "whatever"

Do until cells(Datarow, 1) = "whatever section end is"

......your code here to work on your data

Datarow = Datarow + 1
Loop

There are probably other ways but I've used this method
successfuly for similar worrk to that which you describe.

HTH

Michael Bond

-----Original Message-----
I have a text file with almost 60,000 rows of data
seperated into many different sections. The rows in

each
section have a different number of fields and field
lenghts. Right now, I'm only interested in pulling data
from one section. I'd like to write a macro to go line

by
line until it finds the title of the section I'm
interested in, start reading and parsing the data, then
stop when it finds the name of a new section. I know

how
to read an entire text file and parse data. How can I
make the macro start when it finds the begining of a
section and stop at the end of the section?

Thanks for any help.
.

.


Tom Ogilvy

Parse Text File
 
http://support.microsoft.com/support...eio/fileio.asp
File Access with Visual Basic® for Applications

shows how to read a text file directly if you don't want to open it as a
workbook.

--
Regards,
Tom Ogilvy



"John" wrote in message
...
Thanks for the response Michael, but will this work on a
text file? I'm trying to read the text file directly
using VBA. I don't want to import it first.

John

-----Original Message-----
John

don't know your exact data but something like this may
work:

Dim Datarow as Long

Datarow = 1

....'(assumes first line of data is first row of

worksheet)

Do until cells(Datarow, 1) = "whatever"
Datarow = Datarow + 1
Loop
Cells(Datarow, 1).select

.....'this gets you to the start point of your section
(I've assumed your section has a name which you use in
place of "whatever"

Do until cells(Datarow, 1) = "whatever section end is"

......your code here to work on your data

Datarow = Datarow + 1
Loop

There are probably other ways but I've used this method
successfuly for similar worrk to that which you describe.

HTH

Michael Bond

-----Original Message-----
I have a text file with almost 60,000 rows of data
seperated into many different sections. The rows in

each
section have a different number of fields and field
lenghts. Right now, I'm only interested in pulling data
from one section. I'd like to write a macro to go line

by
line until it finds the title of the section I'm
interested in, start reading and parsing the data, then
stop when it finds the name of a new section. I know

how
to read an entire text file and parse data. How can I
make the macro start when it finds the begining of a
section and stop at the end of the section?

Thanks for any help.
.

.




John[_62_]

Parse Text File
 
Thanks for the website Tom. It was exactly what I was
looking for.

John

-----Original Message-----
http://support.microsoft.com/support...ontent/fileio/

fileio.asp
File Access with Visual Basic® for Applications

shows how to read a text file directly if you don't want

to open it as a
workbook.

--
Regards,
Tom Ogilvy



"John" wrote in

message
...
Thanks for the response Michael, but will this work on a
text file? I'm trying to read the text file directly
using VBA. I don't want to import it first.

John

-----Original Message-----
John

don't know your exact data but something like this may
work:

Dim Datarow as Long

Datarow = 1

....'(assumes first line of data is first row of

worksheet)

Do until cells(Datarow, 1) = "whatever"
Datarow = Datarow + 1
Loop
Cells(Datarow, 1).select

.....'this gets you to the start point of your section
(I've assumed your section has a name which you use in
place of "whatever"

Do until cells(Datarow, 1) = "whatever section end is"

......your code here to work on your data

Datarow = Datarow + 1
Loop

There are probably other ways but I've used this method
successfuly for similar worrk to that which you

describe.

HTH

Michael Bond

-----Original Message-----
I have a text file with almost 60,000 rows of data
seperated into many different sections. The rows in

each
section have a different number of fields and field
lenghts. Right now, I'm only interested in pulling

data
from one section. I'd like to write a macro to go

line
by
line until it finds the title of the section I'm
interested in, start reading and parsing the data,

then
stop when it finds the name of a new section. I know

how
to read an entire text file and parse data. How can I
make the macro start when it finds the begining of a
section and stop at the end of the section?

Thanks for any help.
.

.



.



All times are GMT +1. The time now is 09:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com