+ Reply to Thread
Results 1 to 9 of 9

Using Find() on a text file.

  1. #1
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Using Find() on a text file.

    I have a text file of data and I need to remove a subset of the data into excel. For example, I might have a 500 kb file with the specific word "[the_car_color]" and need to extract the word that comes right after it. What's an easy way to do this?

    Some code I've found at http://stackoverflow.com/questions/1...eas-close-file

    Please Login or Register  to view this content.
    The above code replaces the text I'm looking for. It doesn't extract it to excel like I need.

    EDIT: I won't needlessly bump this thread since the error was a spelling mistake.
    Last edited by 111StepsAhead; 04-16-2013 at 08:39 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using Find() on a text file.

    can you attach a sample txt file for testing ?
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Using Find() on a text file.

    Hi, 111StepsAhead,

    maybe loop and use InStr for each input to decide whether to put the data into the cells or not:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Find() on a text file.

    If you want the first word after '[the car colour]' in file G:\OF\example.txt a oneliner will do:

    Please Login or Register  to view this content.



  5. #5
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Using Find() on a text file.

    snb,

    Your code does not work for me. I'm comparing what you did to the split() function http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx and I'm not seeing what you are trying to do. Can you elaborate or clarify your code?

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using Find() on a text file.

    maybe
    Please Login or Register  to view this content.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Find() on a text file.

    Did you adapt the filename in the code ?
    Are you sure the file contains the string "[the car colour]" ? (brackets included)

  8. #8
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Using Find() on a text file.

    snb, you missed an "s" in your code. It worked great after that. (sytem should be system)

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Find() on a text file.

    I agree that every sytem should be a system...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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