+ Reply to Thread
Results 1 to 25 of 25

Get strings between two strings in text file and remove the rest

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Get strings between two strings in text file and remove the rest

    Hello everyone
    I have a text file which I would like to refine .. I would like to search for the string
    Please Login or Register  to view this content.
    and this will be the starting point .. but I need the second instance of this string

    and also search for the string
    Please Login or Register  to view this content.
    and this will be the ending point

    I want to remove all the rest of the string. Just to keep the strings between the two desired blocks
    The expected output would be
    Please Login or Register  to view this content.
    In brief to include the starting point but not to include the ending point
    then export the string to another text file in the same path

    Thanks advanced for help
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    Thanks a lot.
    In fact this is simple example but the original file has a lot of quotation marks .. Sorry for confusion
    What I want to focus on is the strings of start and end .. the quotation is just part of the string

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    Quote Originally Posted by YasserKhalil View Post
    In fact this is simple example but the original file has a lot of quotation marks .. Sorry for confusion
    Wait for someone else that UNDERSTANDS what you are trying to do.

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    Thanks a lot Mr. Jindon
    The desired output is in post #1
    In this output there may be a lot of " (quotation marks)
    Sample.txt

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    I don't see you use the starting and ending strings. Those would be as blocks for the desired part
    Please provide me with the whole code as I am confused
    Untitled.png

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    .....................
    Last edited by jindon; 10-15-2018 at 12:59 AM.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    Then
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    Can you provide me with the code as I have problem with trying to apply ?
    Thanks a lot for your patience

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    Post your code.

  12. #12
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    This is the code but I got errors
    Please Login or Register  to view this content.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    What Error?

    It works and just overwriting your original txt file.

  14. #14
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    OOps I don't need to overwrite it .. but to export to another text file
    I am going to my work now and I will try working on it later. I appreciate if you put your own touch
    Thanks a lot

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    You are saying getting errors, so you need to find out it first.

    Regarding overwrite, you need to change following meaningless one line
    Please Login or Register  to view this content.

  16. #16
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    Thanks a lot Mr. Jindon
    This is a working code for the sample provided ..
    Please Login or Register  to view this content.
    But how can I define starting point (as string) >> "start point" and also define ending point (as strng) >> "Dead line"
    I need to define those strings (both the start and the end) in the code itself

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    Please Login or Register  to view this content.

  18. #18
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    This gives me red color which refers to error ..

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    Add one more " at both end... do it for yourself..."""Dead line""", do not ask everything that is easy to fix... no more.

  20. #20
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    May be easy for you
    I tried your suggestion and I got 'Invalid procedure or call'
    Please Login or Register  to view this content.
    Is that right?
    Please Login or Register  to view this content.

  21. #21
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    That's my bad. In the text file the string is "Deal line" not "Dead line" ....
    How can in this case (case of not finding the ending point string) >> to skip the ending point and take the rest of the text file?

  22. #22
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    You already have Inst function to check if the string exists. What's more do you need to know?

  23. #23
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    Thanks a lot Mr. Jindon and thanks a lot for your patience
    I have fixed that last point
    Please Login or Register  to view this content.
    Trying to see the code on original code I found that the starting point doesn't deal with the second occurrence of the string but it deals with the last occurrence of it

    I just need to deal with the second instance of this string "start point" ..

    Try this sample please
    Attached Files Attached Files

  24. #24
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Get strings between two strings in text file and remove the rest

    Use the variable for the counter when do loop to find the position of 2nd appeared target string. end exit do.

  25. #25
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Get strings between two strings in text file and remove the rest

    Thank you very much for guiding me
    Please Login or Register  to view this content.
    Thank you very much

+ 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. Swap Specific Text Strings in a Range and Indicate new Strings Not already in Code.
    By liquidmettle in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-17-2018, 01:31 PM
  2. Replies: 2
    Last Post: 03-07-2013, 02:34 AM
  3. Help searching an array of text strings for common strings
    By ABComp in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-23-2012, 11:19 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