+ Reply to Thread
Results 1 to 16 of 16

Macro neede to open text files from folder and remove all the lines except specific lines

  1. #1
    Forum Contributor
    Join Date
    04-09-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    176

    Macro neede to open text files from folder and remove all the lines except specific lines

    Hi to all VBA Programmers,

    I have a folder, it contains some 15 text files. Each files contains some headings like -chromosomes from 1 to 12 and some lines under each chromosome. Now i want keep one heading (for example Chromosome1) with its lines and remove rest of the headings. for example i want to keep this -Chromosome 1 and its lines (BTX) until next _Chromosome start like this i want do it for remaining -Chromosomes) I am doing this manually but it is taking lot of time to complete one single time like this i have to do 12 times.
    Can any one help me with macro code? if yes your efforts would be highly appreciated. I am attching one of the sample file for better understanding of what i am saying.
    Thanks in advance,

    Regards,
    Genetist
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro neede to open text files from folder and remove all the lines except specific l


    Hi,

    attach a corresponding desired result file …

  3. #3
    Forum Contributor
    Join Date
    04-09-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: Macro neede to open text files from folder and remove all the lines except specific l

    Dear Marc L please find my expected result file
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Amend and try this demonstration !


    Please Login or Register  to view this content.
    Standard VBA statements that you can find out in inner help …

    And don't forget to click on bottom left star "Add Reputation", thanks !

  5. #5
    Forum Contributor
    Join Date
    04-09-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: Amend and try this demonstration !

    Dear Marc L
    Thank you very much for your help towards solving my problem but i am getting error her
    Please Login or Register  to view this content.
    once again thanks lot
    Regards,
    Genetist

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro neede to open text files from folder and remove all the lines except specific l


    Works like a breeze on my side ‼ You forgot to amend the default folder path !

  7. #7
    Forum Contributor
    Join Date
    04-09-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: Macro neede to open text files from folder and remove all the lines except specific l

    Dear Marc L,

    Thank you very much your code is working fine but i need still some more changes because your code catching only -Chrosome 1 in output1 thats o.k for first -Chromosome 1 but like -Chromosome i have other from -Chromosome 2 to -Chromosome 12 and iin second round from the same file i want to keep data belongs to -Chromosome 2 then remove all the data like your code doing for -Chromosome1.
    Thanking you very much

    Regards,
    Genetist.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro neede to open text files from folder and remove all the lines except specific l


    It's only a demonstration to show you a way, as requested in original post, a base code to amend …
    Chromosome number criteria is at end of line #15.
    Last edited by Marc L; 09-29-2014 at 03:55 AM.

  9. #9
    Forum Contributor
    Join Date
    04-09-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: Macro neede to open text files from folder and remove all the lines except specific l

    Dear Marc L

    Thank you very much ,
    working fine and i added reputation to you and you really deserve for it
    Once again thanks

    Regards,
    Genetist

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro neede to open text files from folder and remove all the lines except specific l


    Thanks !

    But maybe I didn't understand your real need : extract to independant txt files all "-Chromosome " at once ?

  11. #11
    Forum Contributor
    Join Date
    04-09-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: Macro neede to open text files from folder and remove all the lines except specific l

    Yes Dear MARC L,

    I wish to have like that only instead of running and getsingle file
    Thanks
    Regards,
    Genetist

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    04-09-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: Macro neede to open text files from folder and remove all the lines except specific l

    Hi Dear MARC L,
    Thanking you very much for your kind reply and your time spend in solving my problem. Your code is working perfectly but i need some small change in that. I want to extract -Chromosome 1 from all the files and result will be output1, -Chromosome 2 from all the files and will be output2 like this i have 15 txt files and 12 -Chromosomes and i should get 12 outputs. I knew you can do anything if we explained you very well hope it is lacking from my side. Your solution is highly appreciated.
    Thanking you very much,
    Regards,
    Genetist

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro neede to open text files from folder and remove all the lines except specific l


    I need first two sample source txt files and one result file to be sure of the needed output.

    How do you select source txt files ? How to separate source from output files in same folder ?
    Or is there a source folder and an output folder ? Any order or sort from source files ?

    'cause of many ways, the more you explain the better will be the code …

  15. #15
    Forum Contributor
    Join Date
    04-09-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: Macro neede to open text files from folder and remove all the lines except specific l

    Hi Marc L,
    Thank you very much for your reply. Please find my source file and results file attachments to solve this issue. I have some files in a folder like pic1 (original data)and each file contains -Chromosome 1 to 12 and i want to separate these -chromosomes from those files as separate files. Please see my source file and expected file.
    Thanking you,
    Regards,
    Genetist
    Attached Images Attached Images
    Attached Files Attached Files

  16. #16
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro neede to open text files from folder and remove all the lines except specific l


    Can't do anything !

    Read again post #14 and attach two source files and one result file accordingly to yours needs
    and well answer to questions …

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. pull specific lines from multiple txt files ?
    By brianlg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2014, 06:00 PM
  2. Macro to Open specific files in a Folder
    By lorena.tgarza in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-15-2012, 09:01 AM
  3. [SOLVED] Macro to Delete useless lines, rearrange by dates and skip lines between different days.
    By Tmc2159 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-12-2012, 02:15 PM
  4. Open .TXT file Replace Specific Lines with Cell Values
    By Tellm in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-09-2011, 12:08 PM
  5. Formulas to remove specific lines of text from a spreadsheet
    By visionwindowfilms in forum Excel General
    Replies: 11
    Last Post: 02-28-2010, 06:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1