+ Reply to Thread
Results 1 to 8 of 8

Help Parsing Text File into Rows & Columns Based on Values

  1. #1
    Registered User
    Join Date
    05-25-2012
    Location
    Colorado
    MS-Off Ver
    Excel 2007
    Posts
    8

    Help Parsing Text File into Rows & Columns Based on Values

    Hello All,

    Trying to import a text file into excel to create a table. It looks something like this:

    Please Login or Register  to view this content.
    What I want to do is create a new row every time "BEGINSUB" appears. Then I want to create a column in that row for each of the following:

    -PURPOSE (if it appears)
    -XML Nodes (noted by "!/document", "!document", "ns", or "/ns")
    -FLWSYM

    If there are multiple lines of XML code, then I want a column for each one. Ideally I could have the VBA code add a column if necessary.

    If something doesn't appear after BEGINSUB (like PURPOSE, then it leaves that column blank and looks to insert the next line into the appropriate header column)

    I hope this is a good explanation of what I'm looking for. Please ask questions for any clarification needed. And help is very much appreciated!!! :D

    Thanks and Cheers,
    Jamie

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Help Parsing Text File into Rows & Columns Based on Values

    Hello griffinco,

    Welcome to the Forum!

    You should post a copy of the text file to to aid developing a solution.

    To Attach a File:

    1. Scroll down to the window below your post Additional Options
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    05-25-2012
    Location
    Colorado
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Help Parsing Text File into Rows & Columns Based on Values

    Copy that Leith!

    Here ya go (shortened so it's not ridiculously large, but includes all the types of things I would like to parse.)

    excelparsinghelp.txt

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Help Parsing Text File into Rows & Columns Based on Values

    Hello griffinco,

    The macro has been tested on the file you posted. When "BEGINSUB" is detected a new line is started with the first column containing what followed "BEGINSUB". A new column is filled on this row if the follow are found anywhere in the text: FLWSYM, PURPOSE, ns, /ns. These comparisons are case sensitive to avoid the "NS" in "BEGINSUB" from being the same as "ns" elsewhere. The "ns" string is expected to have zero or more characters after it followed by a colon. This was based on your file. If this needs to be changed, let know.

    The macro assumes your will be copying the data to active sheet and starts with cell "A1". This can changed if needed. You will prompted o locate the file to be opened. This seems like a better option than hard coding the path and file name into the macro. Let me know if any changes need to be made or you have any problems.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-25-2012
    Location
    Colorado
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Help Parsing Text File into Rows & Columns Based on Values

    Wow, Leith! This is impressive, thank you!

    I ran the macro, opened the file (same one I placed in the forum here) and got a "Type mismatch" notification error. Perhaps I did something wrong running the macro?

    Cheers,
    Jamie

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Help Parsing Text File into Rows & Columns Based on Values

    Hello griffinco,

    That was my fault. I forgot the double quotes around "False". The correct is...
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-25-2012
    Location
    Colorado
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Help Parsing Text File into Rows & Columns Based on Values

    Worked like a champ! Thanks Leith!!!

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Help Parsing Text File into Rows & Columns Based on Values

    Hello griffinco,

    You're welcome. Have a good Memorial Day weekend.

+ 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