Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
D.Parker
 
Posts: n/a
Default Search/Extract Data w/in Text File

Hello again! I am searching within a text file for the last row within the
file. After I locate the row I need to separate the data and place into
multiple cells on my worksheet. The code I have is as follows:

Dim TextPath As String
Dim DelimSrchChar As String
Dim METtime As String

Dim DataBuffer As Variant
Dim NCData As Variant

Dim DelimPos As Integer
'===============================================

DelimSrchChar = ","

TextPath = "C:\Temp\Formatted_NC_SN1008.txt"

Open TextPath For Input As #1 'open text file for SN1008

Do While Not EOF(1) 'go while not end of text file

Line Input #1, NCData

If EOF(1) Then
DelimPos = InStr(NCData, DelimSrchChar)

MsgBox DelimPos

Application.Cells(1, 2) = NCData

End If

Loop

Close #1

End Sub

NCData looks like this: 000:03:42:53,3.40426,20.,18.9623. I can get the
data, but I am having trouble finding a method for parsing the data and
placing the parsed data into multiple cells.

The problem: I can use the InStr function to get the data to the left of
the first delimiter as position 13 (i.e. 000:03:42:53) , but how can I get
the data between delimiter positions 13 and 21 (i.e. 3.40426) and between
delimiter positions 21 and 26 (i.e. 20.XX), and to the right of delimiter
position 26 (i.e. 18.9623)? The data sizes can change so they are not
necessarily fixed.

Thanks you.

D.Parker
  #2   Report Post  
Gary's Student
 
Posts: n/a
Default

Let's assume that you are parsing on the coma. First read the data into a
single column as text. Then use the text to columns feature to do the
parsing for you.

In the worksheet this is Data Text to Columns..
In VBA its something like:

Selection.TextToColumns
--
Gary's Student


"D.Parker" wrote:

Hello again! I am searching within a text file for the last row within the
file. After I locate the row I need to separate the data and place into
multiple cells on my worksheet. The code I have is as follows:

Dim TextPath As String
Dim DelimSrchChar As String
Dim METtime As String

Dim DataBuffer As Variant
Dim NCData As Variant

Dim DelimPos As Integer
'===============================================

DelimSrchChar = ","

TextPath = "C:\Temp\Formatted_NC_SN1008.txt"

Open TextPath For Input As #1 'open text file for SN1008

Do While Not EOF(1) 'go while not end of text file

Line Input #1, NCData

If EOF(1) Then
DelimPos = InStr(NCData, DelimSrchChar)

MsgBox DelimPos

Application.Cells(1, 2) = NCData

End If

Loop

Close #1

End Sub

NCData looks like this: 000:03:42:53,3.40426,20.,18.9623. I can get the
data, but I am having trouble finding a method for parsing the data and
placing the parsed data into multiple cells.

The problem: I can use the InStr function to get the data to the left of
the first delimiter as position 13 (i.e. 000:03:42:53) , but how can I get
the data between delimiter positions 13 and 21 (i.e. 3.40426) and between
delimiter positions 21 and 26 (i.e. 20.XX), and to the right of delimiter
position 26 (i.e. 18.9623)? The data sizes can change so they are not
necessarily fixed.

Thanks you.

D.Parker

  #3   Report Post  
D.Parker
 
Posts: n/a
Default

Thank you for the response. My delimiter is the ",", so I would be parsing
on the comma, but are you suggesting to write to a cell and then write to the
columns? I would like to avoid the first action and go directly to placing
the parsed text data in various cells. I think its possible with this
method, I would have to write the data to the cell and rewrite over that cell
when the TextToColumns action is performed I guess.

D.Parker

"Gary's Student" wrote:

Let's assume that you are parsing on the coma. First read the data into a
single column as text. Then use the text to columns feature to do the
parsing for you.

In the worksheet this is Data Text to Columns..
In VBA its something like:

Selection.TextToColumns
--
Gary's Student


"D.Parker" wrote:

Hello again! I am searching within a text file for the last row within the
file. After I locate the row I need to separate the data and place into
multiple cells on my worksheet. The code I have is as follows:

Dim TextPath As String
Dim DelimSrchChar As String
Dim METtime As String

Dim DataBuffer As Variant
Dim NCData As Variant

Dim DelimPos As Integer
'===============================================

DelimSrchChar = ","

TextPath = "C:\Temp\Formatted_NC_SN1008.txt"

Open TextPath For Input As #1 'open text file for SN1008

Do While Not EOF(1) 'go while not end of text file

Line Input #1, NCData

If EOF(1) Then
DelimPos = InStr(NCData, DelimSrchChar)

MsgBox DelimPos

Application.Cells(1, 2) = NCData

End If

Loop

Close #1

End Sub

NCData looks like this: 000:03:42:53,3.40426,20.,18.9623. I can get the
data, but I am having trouble finding a method for parsing the data and
placing the parsed data into multiple cells.

The problem: I can use the InStr function to get the data to the left of
the first delimiter as position 13 (i.e. 000:03:42:53) , but how can I get
the data between delimiter positions 13 and 21 (i.e. 3.40426) and between
delimiter positions 21 and 26 (i.e. 20.XX), and to the right of delimiter
position 26 (i.e. 18.9623)? The data sizes can change so they are not
necessarily fixed.

Thanks you.

D.Parker

  #4   Report Post  
Gary's Student
 
Posts: n/a
Default

You can avoid over-writing you input data if you wish.

Try the process out manually to get the feel of it. Then use the recorder.
It will help define the many parameters that Selection.TextToColumns requires.

I hope this is of some value to you.
--
Gary's Student


"D.Parker" wrote:

Thank you for the response. My delimiter is the ",", so I would be parsing
on the comma, but are you suggesting to write to a cell and then write to the
columns? I would like to avoid the first action and go directly to placing
the parsed text data in various cells. I think its possible with this
method, I would have to write the data to the cell and rewrite over that cell
when the TextToColumns action is performed I guess.

D.Parker

"Gary's Student" wrote:

Let's assume that you are parsing on the coma. First read the data into a
single column as text. Then use the text to columns feature to do the
parsing for you.

In the worksheet this is Data Text to Columns..
In VBA its something like:

Selection.TextToColumns
--
Gary's Student


"D.Parker" wrote:

Hello again! I am searching within a text file for the last row within the
file. After I locate the row I need to separate the data and place into
multiple cells on my worksheet. The code I have is as follows:

Dim TextPath As String
Dim DelimSrchChar As String
Dim METtime As String

Dim DataBuffer As Variant
Dim NCData As Variant

Dim DelimPos As Integer
'===============================================

DelimSrchChar = ","

TextPath = "C:\Temp\Formatted_NC_SN1008.txt"

Open TextPath For Input As #1 'open text file for SN1008

Do While Not EOF(1) 'go while not end of text file

Line Input #1, NCData

If EOF(1) Then
DelimPos = InStr(NCData, DelimSrchChar)

MsgBox DelimPos

Application.Cells(1, 2) = NCData

End If

Loop

Close #1

End Sub

NCData looks like this: 000:03:42:53,3.40426,20.,18.9623. I can get the
data, but I am having trouble finding a method for parsing the data and
placing the parsed data into multiple cells.

The problem: I can use the InStr function to get the data to the left of
the first delimiter as position 13 (i.e. 000:03:42:53) , but how can I get
the data between delimiter positions 13 and 21 (i.e. 3.40426) and between
delimiter positions 21 and 26 (i.e. 20.XX), and to the right of delimiter
position 26 (i.e. 18.9623)? The data sizes can change so they are not
necessarily fixed.

Thanks you.

D.Parker

  #5   Report Post  
D.Parker
 
Posts: n/a
Default

It was of very great value to me! Thank you very much, the macro recorder
gave me a better feel.

Thanks again.

D.Parker

"Gary's Student" wrote:

You can avoid over-writing you input data if you wish.

Try the process out manually to get the feel of it. Then use the recorder.
It will help define the many parameters that Selection.TextToColumns requires.

I hope this is of some value to you.
--
Gary's Student


"D.Parker" wrote:

Thank you for the response. My delimiter is the ",", so I would be parsing
on the comma, but are you suggesting to write to a cell and then write to the
columns? I would like to avoid the first action and go directly to placing
the parsed text data in various cells. I think its possible with this
method, I would have to write the data to the cell and rewrite over that cell
when the TextToColumns action is performed I guess.

D.Parker

"Gary's Student" wrote:

Let's assume that you are parsing on the coma. First read the data into a
single column as text. Then use the text to columns feature to do the
parsing for you.

In the worksheet this is Data Text to Columns..
In VBA its something like:

Selection.TextToColumns
--
Gary's Student


"D.Parker" wrote:

Hello again! I am searching within a text file for the last row within the
file. After I locate the row I need to separate the data and place into
multiple cells on my worksheet. The code I have is as follows:

Dim TextPath As String
Dim DelimSrchChar As String
Dim METtime As String

Dim DataBuffer As Variant
Dim NCData As Variant

Dim DelimPos As Integer
'===============================================

DelimSrchChar = ","

TextPath = "C:\Temp\Formatted_NC_SN1008.txt"

Open TextPath For Input As #1 'open text file for SN1008

Do While Not EOF(1) 'go while not end of text file

Line Input #1, NCData

If EOF(1) Then
DelimPos = InStr(NCData, DelimSrchChar)

MsgBox DelimPos

Application.Cells(1, 2) = NCData

End If

Loop

Close #1

End Sub

NCData looks like this: 000:03:42:53,3.40426,20.,18.9623. I can get the
data, but I am having trouble finding a method for parsing the data and
placing the parsed data into multiple cells.

The problem: I can use the InStr function to get the data to the left of
the first delimiter as position 13 (i.e. 000:03:42:53) , but how can I get
the data between delimiter positions 13 and 21 (i.e. 3.40426) and between
delimiter positions 21 and 26 (i.e. 20.XX), and to the right of delimiter
position 26 (i.e. 18.9623)? The data sizes can change so they are not
necessarily fixed.

Thanks you.

D.Parker

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
Excel data query locks source file jim.bahr Excel Discussion (Misc queries) 0 June 10th 05 06:48 AM
Convert excel file to flat text file Gary's Student Excel Discussion (Misc queries) 0 June 1st 05 01:17 AM
Formatting of Data from .CSV file Night Owl Excel Worksheet Functions 0 May 10th 05 06:40 PM
Append the data given in diff sheets of an Excel File to one sheet sansk_23 Excel Worksheet Functions 3 May 10th 05 03:00 AM
problem working with time data imported from text file afaqm Excel Worksheet Functions 1 February 24th 05 09:02 AM


All times are GMT +1. The time now is 08:27 AM.

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"