+ Reply to Thread
Results 1 to 10 of 10

To read many text files and write it in the excel file

  1. #1
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    To read many text files and write it in the excel file

    Hi everybody

    I need help for reading data from text files and saving it under different columns in the excel file using vba macro.

    For example: I have many text files in the following format

    File 1:
    1 2 3 4
    1 3 5 7
    1 3 1 8

    File 2:
    1 2 3 4
    1 3 5 7
    1 3 1 8

    In excel file the above files should be saved one below the other seperated by the name of the text file, in seperate coumns as found in the text file.

    I found an example online but it saves the data under a single column only. I tried changing it to my requirement, but I couldn't. I have attached the example that I found online.

    Thanks
    Bharath
    Attached Files Attached Files
    Last edited by nynamyna; 12-17-2009 at 01:48 PM.

  2. #2
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: To read many text files and write it in the excel file

    Have you tried to import the text file into excel?

    Are the text files always delimited in the same way?

    Can you post a sample of the text file you want to import, not the code you found somewhere?

  3. #3
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    Re: To read many text files and write it in the excel file

    HI
    Try the macro in the attached file
    Ravi
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: To read many text files and write it in the excel file

    Hi Ravi

    Thanks for the macro......I want the data to be imported slightly different....That is if I have four coulmns in the text file then when we import it should also be saved in different columns in the excel sheet........I have attached the sample of the format needed and the sample text file.....sorry I should have given it before......Sorry for not telling it clearly......

    Thanks
    Bharath
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    Re: To read many text files and write it in the excel file

    Hi
    Save the file inside the folder with text files and run the macro.
    Ravi
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: To read many text files and write it in the excel file

    Hi Ravi

    Thanks for the help....It is reading and writing the file in the same way I want.....Thank you very much....

    Bharath

  7. #7
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: To read many text files and write it in the excel file

    Hi Ravi

    I need a small help.....I just need a small modification .......now the data is saved one below the other.....It would be easy for writing the count if it is saved one next to the other horizonatlly.......I tried doing it but I couldn't find the exact part of the code which does it.....I have attached the sample file
    sorry I am giving a lot of trouble.......

    Thanks
    Bharath
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    Re: To read many text files and write it in the excel file

    Hi
    The code is modified to collate text files horizontally.
    Ravi
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: To read many text files and write it in the excel file

    Hi Ravi

    Thank you very much for the help......

    Bharath

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: To read many text files and write it in the excel file

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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