Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word VBA- Delete lines in pattern

Status
Not open for further replies.

Hamae

Technical User
Joined
Nov 19, 2003
Messages
6
Location
CA
I don't know anything about VBA. I have a file with 3 million lines of data (it's actually a txt file).

Is there a way to delete lines in a certain pattern e.g. in every 5 lines, keep the 1st line and delete the remaining 4.

Thank you very much!!
 
Hi,

Easiest way would be to suck the data into Excel.

Number each Row using the cell drag feature (can number thousands of lines in a few seconds)

Assuming that your data is in COLUMN A, your row numbers are in COLUMN B, in COLUMN C
Code:
=MOD(B1,5)
and copy down thru your data

Now this column has 0 - 4, Decide which number(s) you want to delete.

sort on COLUMN C and delete the appropriate rows.

Save the data as text or copy the data in COLUMN A and paste special - text into Word.

VOLA! :-)


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks for your advice. I know doing in excel will be easy. But as I said, the file contains 3 million lines and I don't think excel can support such a large number of lines.

Any idea to do it in Word (or wordpard, notepad)?
 
You might want to create a macro to loop a certain number of times. For example, this macro will delete the first line, go down five lines and delete the next, etc for 200 runs.

For i = 1 To 100

Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=5
Next i
Just create the macro you want and put it between the loop statement. Make sure you don't have blank lines, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top