Consulting

Results 1 to 5 of 5

Thread: Loop in .txt file to extract recurring strings

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Apr 2017
    Posts
    66
    Location

    Loop in .txt file to extract recurring strings

    I'm trying to extract two text strings that will have varying numbers of occurrences in a text file (uploaded a sample with two occurrences - sorry, could not upload a .txt file so put in excel text box).

    The strings I want will always follow certain key words so thinking I will use variations of the code below to select the line contents after the following key words:
    1) "Interest Holder Name:" - I want the bank name that follows this
    2) "Document Reference:" - I want the date that follows this

    strIntHlder = Trim(Split(Split(newFileContent, "Interest Holder Name:")(1), " " & vbCrLf)(0))
         
     strDocRef = Trim(Split(Split(newFileContent, "Document Reference:")(1), " " & vbCrLf)(0))
    A couple of issues:

    1) I want to store all occurrences of the text strings (there can be several), can I use a loop to do this in a text file?

    2) The key words will also occur in other areas in the document that I do not want to reference (not shown in the attachment). So, can I isolate a loop range - maybe to a range defined by the first and last text lines shown in the attachment?

    Sorry, could not upload a .txt file so put in excel text box.

    Thanks for any assistance
    Attached Files Attached Files
    Last edited by BrI; 07-11-2017 at 01:36 PM.

Posting Permissions

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