+ Reply to Thread
Results 1 to 6 of 6

importing text file to EXCEL

  1. #1
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346

    importing text file to EXCEL

    I very regularly need to import text file to excel. Text file format is fixed. It is a fixed width format. ie let us say in each line the characters 1-10 represent date, 11-40 name, 41-50 amount etc. I want to automate import the process so that in the excel sheet first col contains the date, next name and third amount. Manually I can do it by opening the file but then I have to go through the wizard, select field width, type of data etc. I want to write a sub so that it will pick the text file and convert to excel with right data type ( date as date, name as text, amount as number ). Please help.

    A V Veerkar

  2. #2
    Forum Contributor stevebriz's Avatar
    Join Date
    09-07-2006
    Location
    Santiago Chile
    Posts
    389
    How is the data separated by space, by comma?
    Can you post one line fo the txt file?
    VBA - The Power Behind the Grid

    Posting a sample of your workbook makes it easier to look at the Issue.

  3. #3
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Quote Originally Posted by stevebriz
    How is the data separated by space, by comma?
    Can you post one line fo the txt file?
    Data is not separated by any delimiter. It is fixed width in the sense first 10 characters are date, next 15 are name, next 10 are amount. Four lines would look like

    12/05/2006A V VEERKAR 123.45
    03/08/2005John Smith 1234567.89
    09/20/2006Gracy Rodrigues 876.54
    01/01/2003ABCDEFGHIJKLMNO1234567.89

    ( Note that first 10 characters make date, next 11 to 25 make name and then 26 to 35 make amount.)

    I hope I have made it clear. No delimiter character separating the fields but each field is always of same width on every line. eg date-10, name-15 and amount-10.

    A V Veerkar
    Last edited by avveerkar; 09-28-2006 at 04:40 PM.

  4. #4
    Forum Contributor stevebriz's Avatar
    Join Date
    09-07-2006
    Location
    Santiago Chile
    Posts
    389
    Ok....clear
    You need to read the text file into array line my line
    and then split the lines by width and position

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Thanks a lot Stevebriz. That is exactly what I wanted.

    A V Veerkar

  6. #6
    Registered User
    Join Date
    03-21-2007
    Posts
    1

    Help with the code

    Hi Stevebriz,

    I'm trying to build a macro similar to that Avveerkar needed but when I try to run the macro, it stops at "Split" with a error message "Sub or Fuction not defined".

    Do you know what is going on? Could you help me?

    Thanks,
    Rijofe

+ 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