+ Reply to Thread
Results 1 to 8 of 8

Import textfile to excel and split (spaces) to column !

  1. #1
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Kiruna
    Posts
    163

    Import textfile to excel and split (spaces) to column !

    Hi

    Is it possible to import a textfile whit VBA to excel and split every (space) to a column) ?

    Textfile
    Hello how old are you ? i am 22 years old
    Please help me im getting nuts

    Excel
    [ ] = Columns
    [A]Hello [B]how [C]old [D]are [E]you [F]? [G]i [H]am [I]22 [J]years [K]old
    [A]Please [B]help [C]me [D]im [E]getting [F]nuts

    I think you get the idea.

    Best regards

    Petter
    Last edited by Petter120; 05-09-2012 at 02:03 PM.

  2. #2
    Forum Contributor Russell Dawson's Avatar
    Join Date
    03-01-2012
    Location
    Yorkshire, England
    MS-Off Ver
    2007
    Posts
    608

    Re: Import textfile to excel and split (spaces) to column !

    Yes, use the "Text to columns" facility - using data type as delimited with spaces separating each field.
    If I helped, please don't forget to add to my reputation. (click on the star below the post)

    If the problem is solved, please: Select Thread Tools (on top of your 1st post) -> Mark this thread as Solved.

    Failure is not falling down but refusing to get up.

  3. #3
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Kiruna
    Posts
    163

    Re: Import textfile to excel and split (spaces) to column !

    Sorry i forgott to say, can it be done whit VBA ?

  4. #4
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Import textfile to excel and split (spaces) to column !

    Petter,

    Turn on your macro recorder and, From the Data tab, select 'From Text File'. Here was the result on my side, which includes what appear to be static arrays near the bottom.

    Please Login or Register  to view this content.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  5. #5
    Forum Contributor Russell Dawson's Avatar
    Join Date
    03-01-2012
    Location
    Yorkshire, England
    MS-Off Ver
    2007
    Posts
    608

    Re: Import textfile to excel and split (spaces) to column !

    If you need help with doing this the following should help.


    In 2007
    Paste data into A1 < Col A should be highlighted
    Select Data tab
    In Data Tools select Text to columns
    Make “delimited” the radio button selection
    Next
    Deselect all except for space as delimiter
    Next
    Each should now be separated
    Format each column as required (text in this case no doubt)

  6. #6
    Registered User
    Join Date
    05-09-2012
    Location
    Des Moines, IA
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Import textfile to excel and split (spaces) to column !

    You can also use the "Split" function to get a string array, as in:
    Please Login or Register  to view this content.
    This may create problems if you have multiple spaces between words, however.

  7. #7
    Registered User
    Join Date
    05-09-2012
    Location
    Des Moines, IA
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Import textfile to excel and split (spaces) to column !

    I forgot to include instructions on how to get the textfile as a string. Here you go:

    Please Login or Register  to view this content.
    You need to have a reference set to "Microsoft Scripting Runtime" (or browse for Scrrun.dll) in Tools -> References

  8. #8
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Kiruna
    Posts
    163

    Re: Import textfile to excel and split (spaces) to column !

    thanks it works great

+ 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