+ Reply to Thread
Results 1 to 42 of 42

import text columns into excel

  1. #1
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    import text columns into excel

    Hi I have a text file in the attached document.
    I don't know how to import only the red columns in excel without the blue colored text and without the divisions " | "
    at the end they must be 18 columns
    I can try importing text text / columns but then
    I don't know how to delete the text in blue.
    max
    Attached Files Attached Files

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: import text columns into excel

    Can you confirm:

    1. Is your source data in .txt format, or .docx ?

    2. Which Excel version you're using?
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    Here at home I have Excel 2007, in the office 365 office.
    I know it's possible to do it with powerquery, an explanation how to do it?
    Thank you
    max

  4. #4
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    The original file is txt, the attached one is docx only to highlight the colored columns

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: import text columns into excel

    Please attach the TXT file

  6. #6
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    Here this.
    Attached Files Attached Files

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: import text columns into excel

    Try something like this Power Query:

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    Hi olly i not have power query

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: import text columns into excel

    Hi !

    In this case, according to your post #6 text file, attach at least a workbook for the exact result expected …

  10. #10
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: import text columns into excel

    Quote Originally Posted by max_max View Post
    Here at home I have Excel 2007, in the office 365 office.
    I know it's possible to do it with powerquery, an explanation how to do it?
    Thank you
    max
    Quote Originally Posted by max_max View Post
    Hi olly i not have power query
    I am confused...

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: import text columns into excel


    As the text attachment has many errors, it's better to attach a new one without any
    and with the result expected workbook according to this new text file …

  12. #12
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    For olly:

    In my home = office 2007
    in my office when i work = office365
    in office365 is there powerquery?
    ------------------------------------------------

    For MarcL

    the file txt in post #6 I see no errors
    The end result is as in the post # 1 file doc = 18 colummn
    Last edited by max_max; 06-14-2019 at 07:44 AM.

  13. #13
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: import text columns into excel

    Yes, in Office 365 there is Power Query.

    See the link in my signature for advice on how to use the code I gave you...

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: import text columns into excel

    Quote Originally Posted by max_max View Post
    the file txt in post #6 I see no errors
    Just open in Excel your text file sample, well answer to the import assistant and check your columns :
    you will find more than expected and one missing !

    By the way your need is at very beginner level : activate the macro recorder and open the text file …
    Rows to delete are those where column A is not empty, easy !

  15. #15
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    I did so:
    In the fle attached 1 macro created with the recorder
    Copy the txt file post # 6 paste into A1 of the attached workbook
    start macro1
    Now you have to delete empty and invalid lines like the blue lines of the doc post # 1 file
    Attached Files Attached Files

  16. #16
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation


    Before running any code, once the text pasted to the worksheet, check first around row #55,
    don't you see the huge error ?‼ Two lines on the same row !

    What is the date format in this text file : MDY, DMY ?
    Don't you see the error for the second date column as the text separator is missing ?
    As you used a workaround with the fixed width but the easy way (in order to delete the undesired rows)
    with a correct file is the delimiter way … So you lose the second line on the same row !
    With your way, to delete unwanted rows is to check if first column is text instead of a number …

  17. #17
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    I see no errors in line 55 after pasting the text
    The date format for the 3 columns is in Italian G/M/A (D/M/Y)



    Creazione Iniz.lav fine lavor
    ---------- -------- ----------
    04/07/2016 5072016 08/07/2016


    The date of the second column is in the txt file without /
    the other 2 dates have /

  18. #18
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    As I wrote to open the text file in Excel - like any workbook - but you copy the text,
    share at least your filled workbook instead of an empty one like in your post #15 !
    I hope you test with the same text file attachment from post #6 …

  19. #19
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    The attached workbook is the same as the post # 15 file with the post # 6 txt pasted
    select column A start macro1
    Attached Files Attached Files

  20. #20
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: import text columns into excel


    So check row #56 of this attachment : two lines in the same row ! …

  21. #21
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    Now I've seen ...
    The division into columns text is not so exact
    However, the result must be like the last workbook

  22. #22
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    So since the beginning I suspect it's very not the original source text file will all the errors I've seen
    as I can't imagine someone created such a data file except if it's an idiot ! With a correct file it's so easy !

    So from your last attachment use a helper column with a formula to check if cell in column A is text so it returns TRUE
    and if not text obviously it returns FALSE.
    Then you sort all the range upon this helper column : all the TRUE rows to delete are at the end of the range
    so it's easy to clear the block at once ! Then you clear the helper column, that's it !

  23. #23
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    O.k. I leave my macro.

    A help for this?
    The date format for the 3 columns is in Italian G/M/A (D/M/Y)


    Creazione Iniz.lav fine lavor
    ---------- -------- ----------
    04/07/2016 5072016 08/07/2016


    The date of the second column is in the txt file without /
    the other 2 dates have /

    5052015 which then in Excel becomes with customized cell format gg/mm/aaa ##########
    15052015 which then in Excel becomes with customized cell format gg/mm/aaa 15/05/2015

  24. #24
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: import text columns into excel


    Your date issue is your bad as when you used the Macro Recorder you did not well answer to the assistant for each column format …

    So the easy way is to reactivate the Recorder, open the text file by the same way when you open a workbook
    - better than manually pasting the data ! - and well answer to the assistant, in particular for the columns date format
    and for the decimal separator via the "Advanced" button …

  25. #25
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    I rebuilt the procedure with the recorde, but no options for choosing the date but only the format year month day

  26. #26
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow


    Sorry, I misread but you can try to update the FieldInfo in your recorded procedure
    with the same second parameter than previous or next column, I think it's 4 …
    Who is the fool who created this file ?‼

  27. #27
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    Do you mean the txt file or the macro/workbook?
    All 3 columns for date are set GMA date

  28. #28
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: import text columns into excel


    Yes, who is the dumb who created the source text file ?! Many errors …

    So if the Excel assistant can't transform the column as date, once the undesired rows deleted (or cleared),
    you may use a code or a formula …

  29. #29
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    Exactly what I'm looking for is finding a custom cell format to transform the date or a vba that adds " / " to dates

  30. #30
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    Excel mysteries.
    The attached txt file is a part of the txt file of post # 5.
    It's just the dates.
    I don't understand why these dates in the macro text / columns then become exact in the central column without #########
    Attached Files Attached Files

  31. #31
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question


    Not on my side, maybe it depends on which options you choosed, if you have recorded a code, I wanna see it …

  32. #32
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb


    As this well works on my side :

    PHP Code: 
    Sub Macro0()
             Const 
    "D:\Tests4Noobs\new text.txt"
             
    If Dir(F) = "" Then Beep: Exit Sub
        With Workbooks
    .Open(F).Sheets(1).UsedRange
            
    .Replace "| ""|0"xlPart
            
    .TextToColumns xlDelimitedOther:=TrueOtherChar:="|"FieldInfo:=Array([{1,9}], [{2,4}], [{3,4}], [{4,4}])
        
    End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 06-15-2019 at 06:22 AM. Reason: optimization for non existing file …

  33. #33
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    The txt file is inside the folder
    C:\Users\massimo\Desktop
    but mistake here

    With Workbooks.Open("C:\Users\massimo\Desktop\new text.txt").Sheets(1).UsedRange

  34. #34
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow


    As I shared how I get the correct dates … I have just edited my previous post, try it after updating the F constant …

  35. #35
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    Ok. marcL now no error works and the dates are all correct.
    But for the other txt file?

  36. #36
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    So it was your bad (wrong file path) as the open codeline is the same ‼

    As Excel well converts strings to dates without "/" or "-" for 8 characters strings like "01062019" and not if "1062019"
    so you just have to add a zero for 7 characters strings before the conversion …

  37. #37
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    I'm sorry, marcL, I didn't understand the last post #36

  38. #38
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question

    As I don't know which part you did not understand …

  39. #39
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    Hi I did this:
    I redid the macro with the recorder with txt post # 6
    I put text / columns in the wizard on the 3 dates
    the date format column 1/3
    the text format column 2
    after importing into excel with the macro the 3 columns I put this format
    column 1/3 custum size dates dd / mm / yyyy
    column 2 custom size standard 00000000
    in the end they look like this:

    12/02/2018 | 02022018 | 05/14/2015
    02/02/2016 | 12022018 | 05/14/2019

    the dates column 2 is now without ##############

  40. #40
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question


    So is it fixed or … ?

  41. #41
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: import text columns into excel

    We say with your help I solved almost everything.
    Thank you.
    One thing now the format for column 2 is custom standard 00000000
    is it possible that it becomes 12/12/2012 or do you need a support column with a formula?

  42. #42
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: import text columns into excel

    It depends, whatever by code or by formula …

    For example for 5072016 just adding a zero like 05072016 then you can use the Excel Convert feature (or Text2Columns via VBA).

    From the beginning the logic is at child level but as your text attachment is so weird with many errors
    - maybe it's only a print catch file but if it was created for an export its author is brain less, at least with some mental desease ! -
    I can't waste time for any workarround without a real text file …

    Now I've to go to see a match, see you maybe tonite or the next day.

+ 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. Import from text files and split into columns in Excel
    By kay007 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-03-2018, 07:22 AM
  2. Import text file that contains rows into excel as columns
    By cbiz in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 03-14-2017, 01:54 PM
  3. Text file to excel columns import
    By ROHAN999 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-27-2013, 01:44 AM
  4. import text to same columns?
    By brianlg in forum Excel General
    Replies: 4
    Last Post: 07-18-2013, 06:42 PM
  5. Import Text File Ddata Into Excel Spreadsheet - Multiple Columns & Rows
    By DOgburn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2012, 04:45 PM
  6. Import Text moves columns
    By djblois1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-08-2010, 03:48 PM
  7. Import Text file Fields as Columns in Excel
    By vijay2482 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2009, 11:05 AM

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