+ Reply to Thread
Results 1 to 7 of 7

Import text files to Excel file

  1. #1
    Registered User
    Join Date
    12-24-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    33

    Import text files to Excel file

    Hello,

    I was wondering if anyone could help me with a code that can be used on an button to open txt files and parse it into the bottom of the list in an table/sheet.
    If you look at the attached file.
    This is the format of the TXT file. There is a seperator | between the columns. So this should be split and added to different columns.
    Please Login or Register  to view this content.
    So "LAGER" should be in column A, "20130314" should be in column B and so on.

    Hope someone can help me with this! I don't know where to start exactly.
    Attached Files Attached Files

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Import text files to Excel file

    Suggest that you record a macro for this by using the Text to Columns button on the Data Ribbon and specifying the pipe character (|) as the delimiter. Then inspect the code to find the line which does the splitting.
    Martin

  3. #3
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Import text files to Excel file

    Hi, place this in sheet1 code
    place a commandbutton on sheet 1

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  4. #4
    Registered User
    Join Date
    12-24-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Import text files to Excel file

    Thank you Sean,

    That works great. I was just wondering. There seems to be a problem when there is a string like 3-6, 6-12 or 12-18 in some of the columns. It gets turned into 41428
    /41614/43435 . I have tried to change the format of the cell to number or text but it doesn't seem to work. Have you got an idea?

    Thanks again!

  5. #5
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Import text files to Excel file

    it sounds like it is reading it as a date.
    Have you tried selecting the whole column and formatting as text or number before imprting the text?
    failing that, if you can add another txt file with additional dat i will take a look

  6. #6
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Import text files to Excel file

    try changing all the 1's in this line to 2's
    this changes the data to text rather than converting to date

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-24-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Import text files to Excel file

    Thanks agin Sean - that works perfectly!

+ 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