+ Reply to Thread
Results 1 to 7 of 7

Need to understand how to parse a .txt file

  1. #1
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Need to understand how to parse a .txt file

    Hi All,

    I have a .txt file that used text to columns in the vba code to split the data into columns.

    The issue is that the data does not end up like in all the appropriate columns. For example lets say col a has names and col b has phone numbers.
    I'd get a result whereby some of the phone numbers end up in col a (when they are supposed to end up in column b)
    Can anyone provide insight into how they would approach this issue?

    I don't have a sample.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,354

    Re: Need to understand how to parse a .txt file

    Think you'd need to post a sample text file and maybe the Excel file you get. To use Text to Columns, you would need the file to be delimited in some way, perhaps by commas or tabs. Sounds like that might be the issue.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


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

    Re: Need to understand how to parse a .txt file

    Hello swade730,

    How is the file delimited: Spaces, Commas, Tabs, or something else?

    What do the phone numbers look like?
    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!)

  4. #4
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Need to understand how to parse a .txt file

    Quote Originally Posted by TMS View Post
    Think you'd need to post a sample text file and maybe the Excel file you get. To use Text to Columns, you would need the file to be delimited in some way, perhaps by commas or tabs. Sounds like that might be the issue.
    The File is delimited, I believe by tabs. In the file itself , it's structured such that it includes different information exist under different people. I can't share the file, it's private.
    But let me try to further explain.

    Ultimately this data in the text file needs to end up in excel in particular columns.
    So I can get the note pad data in column A. and then there is this code that looks for a word in col A like
    .Find("Phone Numbers:") or ("Address") or ("Product")...
    So for each one I just mentioned, once that word is found a parse(text to colums) happens. but at the end (once all the criteria is searched). The data ends up in the wrong column because perhaps one name did not have an address, or there was no phone number. it's strange



    I can post that code in a another day or so as an example - it's on my other computer.

  5. #5
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Need to understand how to parse a .txt file

    Quote Originally Posted by Leith Ross View Post
    Hello swade730,

    How is the file delimited: Spaces, Commas, Tabs, or something else?

    What do the phone numbers look like?
    Like the area code will end up in column C and the rest of the numbers in column D (When all should be in column C)

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,354

    Re: Need to understand how to parse a .txt file

    You have data (the text file), code, and a process that the code is meant to fulfil, none of which has been shared with us. You then describe what you think should happen and state that it doesn't happen under some conditions. All well and good when you can see the data and the output. But have limited imagination and I can't picture it.

    Note: the code alone will not be enough. I suggest that you take a live example and edit it in NotePad to remove any sensitive information and remove the bulk of the data.

  7. #7
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Need to understand how to parse a .txt file

    Quote Originally Posted by TMS View Post
    You have data (the text file), code, and a process that the code is meant to fulfil, none of which has been shared with us. You then describe what you think should happen and state that it doesn't happen under some conditions. All well and good when you can see the data and the output. But have limited imagination and I can't picture it.

    Note: the code alone will not be enough. I suggest that you take a live example and edit it in NotePad to remove any sensitive information and remove the bulk of the data.
    OK, will do...I understand how my explanation is confusing. -My apologies. I will try to clone and attach example that is more comprehensible.

+ 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. please help... Commandbutton Code? Please see the attachment file. Do you understand
    By YSNDRVSGL in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-19-2014, 05:50 AM
  2. Replies: 1
    Last Post: 11-13-2013, 01:13 PM
  3. Parse through pdf file via excel vba
    By Lloyd Blankfein in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2012, 07:29 AM
  4. Excel 2007 : Parse Txt file help
    By woodchuck in forum Excel General
    Replies: 4
    Last Post: 07-05-2012, 04:28 AM
  5. Parse Text file
    By noodle48 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-22-2011, 12:14 PM
  6. Parse file name to get name of sheet to use
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-30-2011, 03:55 PM
  7. open the file and parse using VBA
    By smriti in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2010, 11:08 AM
  8. Replies: 1
    Last Post: 09-18-2007, 02:07 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