+ Reply to Thread
Results 1 to 6 of 6

how to import specific row from a txt file into excel using macro ?

  1. #1
    Registered User
    Join Date
    10-28-2013
    Location
    chennai
    MS-Off Ver
    Excel 2007
    Posts
    2

    how to import specific row from a txt file into excel using macro ?

    Buddies, I am looking for some macro help in importing some selective data from txt file to excel. There are around 1 lakh rows in the text file. I want to import only selective 1000 rows. Below are the sample rows in the text file.

    012012031000050040280000050643000079000079000039000079
    012012031000050050000000050643000089000039000039000099
    012012031000050045550000050643000019000039000069000049
    012012031000050045270000050643000088000031900033000019

    1. I want to select only the rows which has the value "4028" starts at position 17 and ends at 20 for import.

    2. While importing the data in the each row should be splitted with fixed width of 6.
    eg. 012012 031000 050040 280000 050643 000079 000079 000039 000079

  2. #2
    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: how to import specific row from a txt file into excel using macro ?

    i think you will need to import the whole text file first
    then
    find the rows with your required value.
    delete other rows.
    then split the data.

    heres a link with dome code to import your text file

    http://excelexperts.com/VBA-Tips-Import-A-Text-File
    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!

  3. #3
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: how to import specific row from a txt file into excel using macro ?

    Try this macro, I did not test it though:

    Edit: forgot to mention, run it on a blank worksheet.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-24-2013
    Location
    Poland
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: how to import specific row from a txt file into excel using macro ?

    I'm not sure, bur probbably it's possoible to import specify rows. Browse through this link
    http://newtonexcelbach.wordpress.com...m-a-text-file/

  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: how to import specific row from a txt file into excel using macro ?

    Hi
    this should work
    run the sub Test
    select your text file
    it will import the data
    remove any rows without 4028
    then split the data into columns
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-28-2013
    Location
    chennai
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: how to import specific row from a txt file into excel using macro ?

    Awesome Millz. . It works perfectly as i expected . .Thanks a lot

+ 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. Excel Macro to Import Specific Data from Txt File
    By Niklasfirst in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-22-2013, 12:41 PM
  2. [SOLVED] import text file to specific excel sheet
    By Danielle22 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-21-2013, 09:13 AM
  3. How to import specific columns from excel file
    By Drehb4life in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2013, 12:55 PM
  4. Import text file into excel and split data in specific sheets
    By chirilaionut in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-03-2013, 07:04 AM
  5. macro to import specific sheets with value in a file
    By aravindhan_31 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2009, 10:55 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