+ Reply to Thread
Results 1 to 3 of 3

Parsing data from text file

  1. #1
    Registered User
    Join Date
    07-13-2009
    Location
    Norwich, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Cool Parsing data from text file

    Dear All, I have a text file which comprises a variable number of blocks of 9 rows of text. Each row is of the format "cGys1 (219.85) cGys2 (109.92) cGys3 (54.96) cGys4 (32.98) cGys5 (10.99)" I need to open the file and extract the numbers between the brackets into succesive columns into a single row of an excel worksheet. The problem i have is the length of the numbers can vary - i.e. 2 or 3 numbers before the decimal place. I'm using Line Input, but then i can't use Mid function as it requires fixed starting positions and fixed string lengths. Parse seems to be the way to go but i cant figure out how to do it. Any help greatly appreciated. Thanks

  2. #2
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Post Re: Parsing data from text file

    It would be useful to have some example code, or example workbook to base this on, but you should be able to use "Mid" you just need to work out what positions you want to extract.

    cGys1 (219.85) cGys2 (109.92) cGys3 (54.96) cGys4 (32.98) cGys5 (10.99)
    Ok, so we have 5 numbers we want to extract.
    How do YOU know which numbers they are? - Each number enclosed within brackets.
    Excel can do the same thing using the InStr function, which will look for one string within another starting at a particular position in the string (optional)

    So something like this, where text_line is your line of text as quoted above:
    Please Login or Register  to view this content.
    I've commented the code so that hopefully you can see how to adjust it to fit your macro, but if you have any questions please do ask
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  3. #3
    Registered User
    Join Date
    07-13-2009
    Location
    Norwich, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Thumbs up Re: Parsing data from text file

    Phil, thats great.

    Problem solved, it works perfectly - easy when you know how

    Thanks so much


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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