+ Reply to Thread
Results 1 to 30 of 30

Opening a text file copying a specific set of info for a list off numbers

  1. #1
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Angry Opening a text file copying a specific set of info for a list off numbers

    Hi guys,

    new to the forum so forgive me if i make any mistakes.

    I have quite a complex macro to run. so i will walk through..

    1) I have a list 3500 unique part numbers starting in Sheet(Parts List)"A1" and running to row end in format 1234567-891, 1234567-892 etc etc.
    2) Each part number has a unique folder saved in location "G:\Trimming" (image 1)
    3) I want to open the .mpf file with the unique part number folder (image 2 - this can be opened by .txt file)
    4) I want to look for the first value that is "0 TR" and copy the next number. (image 3 - the value i am interest in in this case is 7)
    5) I want to copy that value and paste it back into my excel sheet beside the unique part number in my active workbook (image 4)
    6) Repeat until row end.

    See attached photos

    i can understand if this is a long shot....

    image 1.jpgimage 2.jpgimage 3.jpgimage 4.jpg

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    Zip several of the wpd folders with the wpd files and attach them to this post. Also include a sample workbook with part numbers matching the WPD folders.

    I'll need a bit more help with understanding what you want with the TR Number. In the picture that you show there are two of them. Which do you want to list? Also, are they always in the same rows? Otherwise I will assume you want to find them based on the first two characters being "TR."

    It's not that long of a shot: go to the directory matching the part number, open the MPF file, find the TR Number.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    Hi dflak,

    thanks for replying and taking your time.

    I have attached a few document.

    1.) my workbook to sow you where I am currently sitting with my spreadsheet
    2.) a word document explaining what I need more clearly
    3.) zip folder containing Each part number folder and the retrospective MPF folder
    4.) a txt file of my current macro.

    Thanks again.
    Attached Files Attached Files

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    I got enough to get started with, but still have a couple of questions:

    1. What data are you given? I see two tabs, M, K01 and Routing and Parts List. Am I to read the routing and generate the parts list?

    2. Also I still have the same questions about the TR-number. I can find two. They seem to be associated with lines N130 and N140. Can I depend on them being on the same line in the text file every time? Which one do you want to use or do you want to use both, separated by a comma?

    I just noticed something about the data you sent me: the part numbers do not match the directories you sent me. There are over 5,000 part numbers, and 9 directories. None of the 9 directories have a corresponding part number. I will doctor up your data so there are matches.

    Which leads to question number 3: what do you want to do if I can't find a directory for a part number? Do you want a stop-the-program warning message? Do you want me to silently pass over it? Do you want me to write it to a log?

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    I take back what I said about the directory mismatches. The Part numbers use dashes, the directories use underscores. I can work with this.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    One more question. You have duplicate part numbers. Do you want them repeated or do you want a unique list of parts?

  7. #7
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    dflak,

    to answer your questions.

    1) please use the 'parts list' tab and read the part numbers in column A and column C if possible

    2) No we cannot depend on them being the same line each time, we can use the first one that appears (as they always should be the same) - to find the first I always such for "0 TR" and then look for the number after it.

    3) I only sent 9 directories to show you what I mean and what the mpf looks like. There are over 5000 directories also, I just couldn't zip them all. I can send you more if needs me? they are all in the same location each time (G:\Trimming)

    4) If you cant find a directory we can just skip over and im guessing the code will enter N/A?

    if you need any more info let me know.. Appreciate your help!!!

  8. #8
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    just want to clarify,

    when we are searching the part number in the directory from Columns A or C, does it search an exact search, e.g. word for word. Or can it pick up characters?

  9. #9
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    I got ahead of you and assumed that you wanted to use the routing sheet. Attached is a file that does that. It will give you an idea of what things will look like at least. I can change my workbook to look at the parts list.

    Before I go further, if you can tell me how you fill in the workbook now, I will try to make the code match your procedure. For example, I can arrange so that you can copy / paste the routing on the routing sheet, press a button and the parts list and the lookups for the TR-numbers will be generated automatically. I can handle the duplicates caused by the suffixes on the routing sheet.

    Some more notes: I do have enough data to work with. I pared it down to those parts with a matching directory and kept a few that didn't for the purposes of testing. At the moment, I leave a part with a missing directory blank and log it in a separate log file. I can display this information on the main display.

    It does not matter where the TR_numbers are in the file, but I did notice that in the data you provided, most have line numbers starting with N010 or something like that. On these the TR-numbers are on rows 12 and 13 (If I recall correctly). There is one file (1006030_313.WPD) that does not have the line numbers and in this file the TR-numbers are in different rows. I am a bit uncomfortable with making this the means by which I find TR-numbers. I don't know if I have all the patterns down.

    There is a Control Panel Sheet. This is where you tell the program the directory name that contains the WPD directories.
    Attached Files Attached Files

  10. #10
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    P.S. I did a timing test. It took 4 seconds to process 12 part numbers. At this rate it would take a bit under 30 minutes to do 5,000.

  11. #11
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    good stuff,

    What i do is; I fill in the first tab by importing a spreadsheet that was exported from an access database. I then apply my filters to get the parts list I need I copy and paste into tab " M, K01 and Routing" and then delete the old tab (to keep it tidy and a smaller file size). I then copy and paste that data into a new tab name "parts list" and format to get the correct part number format.
    That's as far as I got to..

    if you could copy / paste the routing on the routing sheet, press a button and the parts list and the lookups for the TR-numbers will be generated automatically, that would be even better?

    I see the attached file, that is good however I noticed in Parts List column A needs the "-" replaced with "_" as that's how the parts are saved in the directory, or can the macro overlook this?
    column C in parts list should be the exact same as column A only characters 2 & 3 and the "-" should be deleted also as that's also how some parts are saved in the directory.


    it does not matter where the TR is - although as long as it is somewhere in the G-code i.e has "0 TR" before it.
    they are always the same so I am comfortable with this.

    in terms of the timing, I am not bothered as this will only be done once every week as an audit.

  12. #12
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    OK, one more question then. Do you have control of the access database? We can push the automation back a step further. You can import the data directly from the access database without the need of copy and paste. Also you can set up the windows task scheduler to run this for you automatically in the early hours of the morning so everything is already run and waiting for you when you get in . These things are not as difficult to do as they sound. However, we don't have to do them now. I'll save that as a "teaser."

    I can keep the dash in the parts list for the purposes of display. I'll do the translation in the code.

    I will take it from the copy / paste of the routing - I should be able to give you a prototype later today.

  13. #13
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    No unfortunately I have no control, I can only export to excel..

    however after we get this up and running I can come back around and push for access.

    so as we stand today. I use my macro that I attached to get me as far as I did. are you building on top of it, or starting from scratch? will it be easy to drop a fresh set of part numbers into this each week?

    thanks again for this. I must have a read through your macro to understand as I am still learning myself

  14. #14
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    I plan on starting form scratch. I will document the macro profusely and I'll answer any questions you may have.

  15. #15
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    no problem you have mine there if needed to see how I got where I did. however it looks like a 6 year old made it so itll probably be better this way haha

  16. #16
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    Let's see if this meets your needs or if I have to change anything.

    Here is the prototype.

    The Control Panel sheet is sort of a checklist.

    Cell B2 contains the path to the parent directory containing the WPD directories.

    Clicking on the Clear Routing button clears the Excel Table on the M, K01 and Routing sheet. All you will need to do is copy and paste the routing into cell A2 on this sheet.

    There is a helper column (I) that has the formula =MATCH([@Part],[Part],0) = ROW()-1. This formula is True only for the first occurrence of the part number in column H. I use this in the code. I only process Trues.

    Column I can be hidden. Since this is an excel table, the formulas in columns H & I are “remembered” and copied down automatically for each row pasted into the table. You will also notice that the formulas are defined in terms of column headers instead of cryptic column letters. All this is part of working with tables.

    Here is some more information on Excel Tables: http://www.utteraccess.com/wiki/Tables_in_Excel.

    Excel Tables also make the VBA coding a lot easier.

    Clicking on the Make Parts List Button on the Control Panel runs the program.

    The program does several things.

    Internally, it makes the WPD sub-directory name from the Part Number

    It checks to see if this directory exists – if it does not, it writes out “N/A – no directory.”

    Then it checks to see if the file, MPF1.MPF exists in this directory – if it does not, it writes out “N/A – no file.”

    If it passes both these tests, it opens the file and looks for the string “ZOA” – I am assuming that the TR numbers are on the two rows after this string.

    If it cannot find this string, it returns a row number of zero and the program writes out “N/A – not found.”

    Finally if everything passes, it gets the next two lines and prints out the TR-numbers in columns B & D.

    As a bonus I record the start and end times in cells B11 and B12 and the elapsed time in cell B13.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    Hi Dfak,

    Perfect!! The idea is correct and everything works,

    however, many are coming up as no directory as Column A has part number "1002690-305" for example and instead it should read "1002690_305". similar with column C it reads "1002690305" and it should read "12690305" (removing the second and third character)

    where does the parts list table come from? copy and paste from Routing? If so could we put a replace function in for - * _, and also column C to remove the 2nd and third character?

    Cheers

  18. #18
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    "1002690-305" should convert to 1002690_305 inside the program.

    I'll need a bit more explanation on how you get 12690305 from 1002690_305. Should I be removing the second and third character from each part number?

  19. #19
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    yes just noticed that after I sent. I apologise..

    there is only 1200 directories yet there are 4000 part numbers so there will be a few missing....

    yes literally just removing the 2nd & 3rd character. (basically our very old CNC machines could not handle more than 8 characters as a title)

  20. #20
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    OK, I'll make that update later today.

  21. #21
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    I think I have it this time.
    Attached Files Attached Files

  22. #22
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Opening a text file copying a specific set of info for a list off numbers

    Try
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    Running perfect. Thanks dflk, appreciate your help.

  24. #24
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    dflak,
    I have been using this macro and it is brilliant.

    Column H is the first 11 characters of column A.
    however the mpf files are only saved in directories that are in odd numbers.

    ie it would find part number 1021487-387 and it would return a directory of TR7 etc, however it will not return a directory for 1021487-388. is there anyway to add in a -1 to the code if the last number is even? I tried doing this manually however itll will not return a value as the part is no a number due to the "-".


    Also if I needed to make changes to the remembered formula in the table where can I find this info?
    thanks
    Last edited by brendanlowrywork; 06-07-2017 at 03:50 AM.

  25. #25
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    This version should take 1 off the part number if the part number is even. So 1002690-306 will be shown as 1002690-306 and the overall part number will be 12690306, but it will look for directory 1002690-305.WPD.

    As for the tables. On the routing sheet, there are formulas in Columns H and I. If you add new part numbers to the end of the table, these formulas will be copied down automatically. If you clear the contents of the table (rows 2 to the end) the formulas will be "remembered" and when you paste in new data into columns A:G, they will be applied automatically.

    On the Parts List table, there are no formulas. Everything is filled in by the program.
    Attached Files Attached Files

  26. #26
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    Hi Dflak,

    just a question regarding this macro;

    it looks at column A the part number

    and applies the formula to get the part number as follows

    2017-07-03_12-15-11.jpg
    2017-07-03_12-15-29.jpg
    id there any way you can update the formula to show the part number in the format 1048758_301 and also in 18758301 (2nd and third character removed)

    2017-07-03_12-15-40.jpg

    some times the part numbers are saved in the two different formats in the directory..

    Thanks

  27. #27
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    Unfortunately I've already purged the test data I had for this. However, all is not lost. I'll need to ask some more questions.

    The part of the code you pointed out adds a "-1" to the expected directory name if the last three digits of the part number in column A are even. The part that tests for the existence of the directory comes a couple of rows later.

    So now you are telling me that the directory name could be 1002690-305 or it could be 12690305 or in the case of an even number: 1002690-306-1 or 12690306-1.

    If this is the case, then I'll have to add a bit of code between the two pieces of existing code to test if either of these directory names exist and use the proper one. I'll push on in this direction.

  28. #28
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    This version is totally untested.
    Attached Files Attached Files

  29. #29
    Registered User
    Join Date
    06-01-2017
    Location
    Ireland
    MS-Off Ver
    2010
    Posts
    18

    Re: Opening a text file copying a specific set of info for a list off numbers

    DFlak,

    that's correct! you seem to know what I mean!!

    although for some reason the code is timing out at this position.

    2017-07-04_13-50-44.jpg

  30. #30
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Opening a text file copying a specific set of info for a list off numbers

    If I am going to be able to test this, I will need some sample data like I had before.

+ 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. Replies: 1
    Last Post: 09-16-2015, 04:14 AM
  2. Replies: 1
    Last Post: 04-26-2015, 01:58 PM
  3. get info from another excel file without opening it
    By dbrizor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-03-2015, 08:06 AM
  4. List of all row numbers that contain a specific text string
    By spoursy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-09-2015, 07:24 AM
  5. Replies: 4
    Last Post: 01-18-2012, 07:43 AM
  6. Opening EXCEL with a specific file opening also
    By HitTheEXCELerator in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-23-2011, 12:51 PM
  7. Replies: 2
    Last Post: 01-06-2006, 01:45 PM

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