+ Reply to Thread
Results 1 to 19 of 19

Importing specific data from multiple text files in a file directory into excel

  1. #1
    Registered User
    Join Date
    06-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Importing specific data from multiple text files in a file directory into excel

    I have been trying to import specific data from multiple text files in a directory that updates daily. I just need a code that can go through and import the data for the last 1000 text files. I have no prior vba excel programming experience. I have been trying to find codes to manipulate for what I need but i can't get it to work. Below is a template of what the text file looks like. The important data is within the first 11 lines. I only need the number after "Pump ID:" such as "563584", the Date, the number after the "Backlash Value:" such as "786," and the "Read Back Test" result. The way I need is organized is below in the screen shot. Any help will be appreciated. I am using excel 2010.

    XXXXXXX Pump Backlash Log
    Pump ID: 563584 -- 2013_06_21--08-18-01
    Date: Fri, Jun 21, 2013
    Time: 8:20:00 AM
    SW P/N = 004024
    SW Rev = F
    Backlash Loc: 17351
    Backlash Value: 786 HEX Value = 0x028A
    Backlash High Limit: 1425
    Backlash Low Limit: 187
    Read Back Test: PASSED
    ---------------------------LOG DATA----------------------------

    08:18:11.938 <echo1>
    08:18:12.939 [echo1] Ok.
    08:18:12.940 <Version>
    08:18:17.940 <Version>[Version] 35852, 35798, 35809
    08:18:17.940 [MspVersion] 35852, 35798, 35809, 0, 0
    08:18:17.940 <ReadpcbaID>
    08:18:19.940 <ReadpcbaID>[ReadpcbaID] 87810136, 4664, A
    08:18:19.940 <ReadpumpID>
    08:18:21.940 <ReadpumpID>[ReadpumpID] 0, 0,


    I would like it organized into excel like the screen shot below.
    excel screen shot.PNG

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Importing specific data from multiple text files in a file directory into excel

    Hello abat,

    Welcome to the Forum1

    Do you have a list of the files or are the files all in the same folder?
    What is full path of the folder?
    How you determine the "last 1000" files?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Importing specific data from multiple text files in a file directory into excel

    Hi Leith,

    Thanks for responding.

    1)Files are all in th same folder
    2)The folder path is "S:\Share\MfgMTE\BackLashLogFiles"
    3)Last 1000 files are determined by the date they were uploaded to the folder

    Thanks,
    Ayman

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Importing specific data from multiple text files in a file directory into excel

    Hello Ayman,

    Thanks for getting back to me.

    Are the dates of the last uploaded files all the same date?

  5. #5
    Registered User
    Join Date
    06-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Importing specific data from multiple text files in a file directory into excel

    So the dates can change because upto 50 or 60 files can be uploaded per day. I hope the screen shot below will explain. I base dates of the files on the "date modified" column of the folder.

    folder dates.PNG

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Importing specific data from multiple text files in a file directory into excel

    Hello Ayman,

    The code below is based on what you have told me so far. The macro GetPumpData will prompt you for the starting and ending dates of the files. It will then open every text file within those dates in the specified folder and transfer the data to "Sheet1" of the workbook. You can change the sheet name if you need to. Copy and paste the code into a VBA module. You can either attach the macro to a button to call it or manually run from the Macro Dialog by pressing the keys ALT 8.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Importing specific data from multiple text files in a file directory into excel

    Hey Leith,

    Tried the code today. But it keeps highlighting the Read Back Test line in the code in red and yellow. I included an image below. What does it mean?
    code error.PNG

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Importing specific data from multiple text files in a file directory into excel

    Hello Ayman,

    The error indicates to me that the text file does not have 11 lines of data. Have you checked the text file manually?

  9. #9
    Registered User
    Join Date
    06-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Importing specific data from multiple text files in a file directory into excel

    Hey Leith,

    It works correctly. I just copied it back in fresh from the start and I have ran it multiple times with no issues. I must have messed something up the first time. Thank You so much!

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Importing specific data from multiple text files in a file directory into excel

    Hello Ayman,

    Glad to hear it is working. I will mark this solved but if you have any other issues, post back in this thread.

  11. #11
    Registered User
    Join Date
    06-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Importing specific data from multiple text files in a file directory into excel

    Leith one more question.

    I changed the code at this line
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    in order to get the date without the day, but now when I run the program the dates are all out of order. I can fix it by hitting sort. I tried running the macro where I sort the data and copy it into the code but it doesnt help. Is there an automatic way to do it?

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Importing specific data from multiple text files in a file directory into excel

    Hello Ayman,

    I made the change and ran the macro. The result was the date without the day.

    Did you reformat the date column?

  13. #13
    Registered User
    Join Date
    06-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Importing specific data from multiple text files in a file directory into excel

    Hi Leith,

    Yes, I reformatted the date column to be "June 14, 2013" instead of "Fri, June 14, 2013." But the dates are still not in order. I was curious if there is coding to include in the original code procedure to get them in order automatically instead of having to go through sorting button.

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Importing specific data from multiple text files in a file directory into excel

    Hello Ayman,

    Do you want the macro to sort the dates in ascending order?

  15. #15
    Registered User
    Join Date
    06-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Importing specific data from multiple text files in a file directory into excel

    Hey Leith,

    I would like the dates to go from new to old and time to go from new to old also.
    I played around with the code a bit. Added the time as a column. So the code looks like this:

    Please Login or Register  to view this content.
    and the second macro I made is below. It sorts by date and time. Combining the two codes would be awesome. I tried but it didn't work.
    Please Login or Register  to view this content.

  16. #16
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Importing specific data from multiple text files in a file directory into excel

    Hello Ayman,

    I have added the extra column and two buttons: one to list the file data and the other to sort the dates from newest to oldest.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    06-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Importing specific data from multiple text files in a file directory into excel

    Leith,

    Your Awesome. Thank You!

    Ayman

  18. #18
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Importing specific data from multiple text files in a file directory into excel

    Hello Ayman,

    You're welcome. It was a fun project.

  19. #19
    Registered User
    Join Date
    06-20-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Importing specific data from multiple text files in a file directory into excel

    Hi Leith,

    I made some changes to my database and everything is working great. One issue I have is that sometimes the Pump ID values are repeated in the column with different read back test because they may have been tested once and failed then tested again and passed. How do I filter or remove the duplicates so that only the most recent record for the Pump ID remains with the most recent read back test.

    The excel document is here: Automatic Data Organizer_Ascending.xlsm

    Below is a screen shot of what Im talking about with the highlighted rows. Sometimes the same Pump ID can occur more than 2 times.
    duplicates.PNG

+ 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