Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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.
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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.
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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.
.

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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.
.

.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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.
.

.



.

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
Parse Text Erin Excel Discussion (Misc queries) 1 June 18th 09 10:17 PM
Parse text Max Excel Discussion (Misc queries) 5 April 3rd 09 04:51 PM
Parse Text Urget Help Max Excel Discussion (Misc queries) 1 April 3rd 09 03:15 PM
Parse File Location Mike Excel Worksheet Functions 5 October 3rd 07 04:05 PM
Parse text & Numbers Jack Excel Worksheet Functions 2 December 18th 04 05:18 AM


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

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

About Us

"It's about Microsoft Excel"