Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Copying certain lines from a text file

Hi, I have a text file with 30,000 lines. I need to figure out a way to copy
only the lines that start with [SC] and the surrounding lines (1 above, 1
below) to my excel sheet. I can import the whole sheet into excel, but I cant
figure out how to sort it and still keep the 3 lines I need together.. Any
help pls? Thank you!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Copying certain lines from a text file

How about importing the whole file into a new worksheet in a different workbook.

Then select column A
Edit|Find
[SC}
Then come up two rows
then Shift-ctrl-home
to select that cell through A1
Edit|Delete|entire row

Then select column A again
With A1 the activecell
Edit|find
[SC]
But shift-click-Find Next
This will start at the bottom and work it's way up to find the last [SC] in the
column.

Come down a couple of cells
select that cell
Shift-Ctrl-End to select that cell through the last used cell

Edit|Delete|entire row

And copy what's left to its proper home.


Michael A wrote:

Hi, I have a text file with 30,000 lines. I need to figure out a way to copy
only the lines that start with [SC] and the surrounding lines (1 above, 1
below) to my excel sheet. I can import the whole sheet into excel, but I cant
figure out how to sort it and still keep the 3 lines I need together.. Any
help pls? Thank you!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 145
Default Copying certain lines from a text file

We would try

Add help column;
Go down whole list row by row;
If Like "SC*" then dirty 3 rows in help column accordingly
Go up help column;
Delete rows with no entry;
Delete help column

--
Regards

"Michael A" wrote in message
...
Hi, I have a text file with 30,000 lines. I need to figure out a way to

copy
only the lines that start with [SC] and the surrounding lines (1 above, 1
below) to my excel sheet. I can import the whole sheet into excel, but I

cant
figure out how to sort it and still keep the 3 lines I need together.. Any
help pls? Thank you!



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Copying certain lines from a text file

Below is a visual basic Macro that will do the trick. Make sure the number
of lines inthe file is a multiuple of 3. If not an errror will occur but you
will stillget results.


Sub read_test()
Const ForReading = 1, ForWriting = 2, ForAppending = 3


fileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.OpenTextFile(fileToOpen, ForReading)

RowCount = 1

Do While f.AtEndOfStream < True

line1 = f.readline
line2 = f.readline
line3 = f.readline

If Left(line2, 4) = "[SC]" Then
Cells(RowCount, "A").Value = line1
RowCount = RowCount + 1
Cells(RowCount, "A").Value = line2
RowCount = RowCount + 1
Cells(RowCount, "A").Value = line3
RowCount = RowCount + 1
End If

Loop

End Sub


"Michael A" wrote:

Hi, I have a text file with 30,000 lines. I need to figure out a way to copy
only the lines that start with [SC] and the surrounding lines (1 above, 1
below) to my excel sheet. I can import the whole sheet into excel, but I cant
figure out how to sort it and still keep the 3 lines I need together.. Any
help pls? Thank you!

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
Inserting Lines or Copying lines with formulas but without data wnfisba Excel Discussion (Misc queries) 2 August 18th 06 04:41 PM
text box insert in Excel - text box lines print on second copy Diana (Berry & Co) Excel Discussion (Misc queries) 0 July 26th 06 04:39 AM
Some lines of text in Excel field do not wrap text. Please help. Michele Excel Discussion (Misc queries) 0 January 5th 06 07:27 PM
Excel, how copy subtotals without copying all lines inbetween? confounded Excel Discussion (Misc queries) 1 December 13th 05 05:55 PM
Copying the Editing in one file to Another opened XLS file Ahmad Excel Worksheet Functions 1 May 27th 05 02:04 PM


All times are GMT +1. The time now is 04:49 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"