+ Reply to Thread
Results 1 to 15 of 15

Export a field from text file to excel and remove duplicates

  1. #1
    Registered User
    Join Date
    11-04-2011
    Location
    Mars
    MS-Off Ver
    Excel 2003
    Posts
    8

    Export a field from text file to excel and remove duplicates

    Hi all,

    I am an new to the forum and I have ended up here as so to resolve my need in vba aswell learn good things in vba and my requirement goes as follows

    I have a folder and the folder has nearly has 350 text files all the text files are of similar patters

    Description of text file :

    Text file has at least 11 fields and at the max of 18 fields with a delimiter " " (space)


    Now I wanted to load only 10th field from the text file to the excel

    Since each and every file has duplicates and also considereing the limitations of excel ( I guess it cant store more than 65000+ records) after importing that field I wanted to remove duplicates and then append with 10th field of next file and remove duplicates for the whole list and on and on till 350 text files



    My 10th field can be maximum of 8 bytes but it can be less than that ( but Its sure 10th field will be present in the file)


    Please note : total size of the folder is around 450 MB ( Total size of all text file)

    If anyone has come across this scenario and the slution used will be helpful for me )


    Please let me know if anymore information is needed for the same.

    Thanks in advance

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Export a field from text file to excel and remove duplicates

    Please attach a couple of text files and a sample of the final excel file so we can help you better.

    BTW, where is Mars?

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Export a field from text file to excel and remove duplicates

    hi, premkrishnan, can you post a couple txt files and result expected on them?

  4. #4
    Registered User
    Join Date
    11-04-2011
    Location
    Mars
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Export a field from text file to excel and remove duplicates

    Apologies as I just cheked few files have a few added format

    So according to the files which changed format

    I need to load data only with string $HASP373 and the rest of the records need to be ignored and the line SRCHFOR '$HASP373' should be ignored


    Sorry again for missing few minor addons before
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-04-2011
    Location
    Mars
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Export a field from text file to excel and remove duplicates

    BTW, where is Mars?
    I am a space lover I know its an impossible task to go out of earth so I thought I would put my location as that

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Export a field from text file to excel and remove duplicates

    So if i understand you correctly, you want a code that will open the first text file, take the column which contains string $HASP373 and copy the contents of the next column into column A of your output file. Then go to file 2, copy the contents into column B of the output file, etc? Is this right?

  7. #7
    Registered User
    Join Date
    11-04-2011
    Location
    Mars
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Export a field from text file to excel and remove duplicates

    Hi Arlu,

    These are the following steps

    1.Open the text file
    2.Copy only the next column after the string "$HASP373" except the record SRCHFOR '$HASP373'
    3.Remove duplicates from the file and save it in one location say x
    4.Open the next text file and do steps 2 and 3 by appending data to location x and eliminating duplicates
    5.do 1 to 4 until all text files are processed

    Hope I am clear now

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Export a field from text file to excel and remove duplicates

    Yes, should the data be appended below or side by side?

  9. #9
    Registered User
    Join Date
    11-04-2011
    Location
    Mars
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Export a field from text file to excel and remove duplicates

    Hi Arlu,

    Append the data below and remove duplicates

  10. #10
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Export a field from text file to excel and remove duplicates

    hi, premkrishnan, please check attachment, run code "test"
    Attached Files Attached Files
    Last edited by watersev; 11-04-2011 at 12:02 PM. Reason: file updated

  11. #11
    Registered User
    Join Date
    11-04-2011
    Location
    Mars
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Export a field from text file to excel and remove duplicates

    Hi Watserv your code is working fine but I am not able to understand it as I was trying to search for the "$HASP373" but couldnt find it.

    Any pointers of what you have done will be helpful for me to have this as base for proceeding with any future requirement.

  12. #12
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Export a field from text file to excel and remove duplicates

    please check attachment, run code "test", it works for the only sample txt file available.

    The line responsible for pattern search has comments.
    Attached Files Attached Files
    Last edited by watersev; 11-08-2011 at 05:14 AM. Reason: Error check added

  13. #13
    Registered User
    Join Date
    11-04-2011
    Location
    Mars
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Export a field from text file to excel and remove duplicates

    Thanks Waterserv

  14. #14
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Export a field from text file to excel and remove duplicates

    please check post #12 as the file and code has been updated to avoid error on processing files that have no pattern inside

  15. #15
    Registered User
    Join Date
    11-04-2011
    Location
    Mars
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Export a field from text file to excel and remove duplicates

    Yes I checked that..Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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