+ Reply to Thread
Results 1 to 16 of 16

Search against separate excel file for existing values, adding next unique identifier

  1. #1
    Registered User
    Join Date
    02-18-2020
    Location
    British Columbia, Canada
    MS-Off Ver
    2015
    Posts
    12

    Question Search against separate excel file for existing values, adding next unique identifier

    Hello all,

    Hoping for some help with adding unique identifiers to a list of... let's call them products. I have attached an excel sheet showing how the input would look and the (hopefully) output. Basically, I would have a long list of these products with a "base name" which is added upon each time the product is used. Think of it as generations.

    In my example, we have three different products that each has an associated quantity. I want the code to look in the Qty column (in this case B) and expand each record by the number indicated and add a unique identifier to the end. The catch is, I also need it to search a list of existing products stored in a separate file to determine if that product has been used before, and if so, what the next unique identifying number would be in the sequence. It would also be nice to be able to dictate what the unique identifier looks like (i.e. maybe it's not always just numerical, maybe we add a symbol after the number) though this is not strictly necessary.

    eg: NAT214-005-006 has already been used 7 times before, so in the master list NAT214-005-006-00X (x=1-7), etc. already exists so the program should be able to recognize this and select NAT214-005-006-008 at which to start numbering.

    Basically 3 separate steps
    1) expand the records according to the values in the Qty column, copying the "base name" into each new row.
    2) search the other excel file with the master list for this base name, and upon finding records, append the unique identifier from -001 to -00X (whatever is next in the sequence).
    3) add these new products to the master list so it remains updated.


    Thank you so much to whoever can help me out with this little problem.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Search against separate excel file for existing values, adding next unique identifier

    Can you share the second file so that the code can reference this other file. There is no master list in the sample file.

  3. #3
    Registered User
    Join Date
    02-18-2020
    Location
    British Columbia, Canada
    MS-Off Ver
    2015
    Posts
    12

    Re: Search against separate excel file for existing values, adding next unique identifier

    Ah, yes, thanks. I have attached a sample master list as it might look for this example.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Search against separate excel file for existing values, adding next unique identifier

    Here is a solution for you. Run the code from the "Sample Excel Sheet Naming" workbook, and you will be prompted to select the "MasterList" Workbook. Let us know how it goes.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-18-2020
    Location
    British Columbia, Canada
    MS-Off Ver
    2015
    Posts
    12

    Re: Search against separate excel file for existing values, adding next unique identifier

    Hi there,

    Wow! That's fantastic! Thank you so much, it works quite well, I hope I'll be able to figure out how to adjust it for different columns etc. (we will be using it with a different header set up etc.). Just a couple adjustments/questions, would there be a way to automatically specify the master file? It's good as is right now as we still need to establish the file but once done, it would be nice to not have to select each time. Also, when I run the macro, the master list changes to read-only, is there a way to change this?

    Thank you

  6. #6
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Search against separate excel file for existing values, adding next unique identifier

    This updated code will not open the master file as read only. The masterList.xlsx file will now open if it is located on the same path as the core file.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-18-2020
    Location
    British Columbia, Canada
    MS-Off Ver
    2015
    Posts
    12

    Re: Search against separate excel file for existing values, adding next unique identifier

    Hi maniacb,

    Thanks so much for your help thus far, you are a real life saver. This code was great for some of our entries, however, now that I am trying to implement
    it on the actual (rather large) list of plant names, there are instances where it doesn't work. I think I am running into some problems where the product
    name has '$' symbols in it. I'm thinking that the code can't recognize these symbols since when I try to run it on plant names with $ symbols it doesn't
    work. Unless it has something to do with the number of digits. Before I was involved in this, there was no consistency with the number of digits added
    (i.e. people would add -1 rather than -001). I have included a sample of some of the problematic names in the master list I am now working with. Is it
    possible to just ignore the '$' and just look at numbers?
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Search against separate excel file for existing values, adding next unique identifier

    I tested the process and the $ is not an issue. As long as the plant name has three digit numbering at the end, the code does work. But none of the test plants you sent have something different than -000 numbering scheme at the end. The only item in the masterlist with different numbering scheme was MOC20P01, with no -000 at the end. Attached is the test Sample file I used with the masterList you sent, I also improved its speed.
    Attached Files Attached Files
    Last edited by maniacb; 02-03-2021 at 01:49 AM. Reason: Add file

  9. #9
    Registered User
    Join Date
    02-18-2020
    Location
    British Columbia, Canada
    MS-Off Ver
    2015
    Posts
    12

    Re: Search against separate excel file for existing values, adding next unique identifier

    Thanks again. I'm curious whether the lack of 000 formatting could cause a runtime error '5'. The macro was working well, but now can't seem to get past the bolded line below. If stuff in the master file doesn't match this format, would that cause this error? If so I may be able to remove them, but it would be nice to be able to add some code to simply skip over thing that don't follow the "-000" format.
    For i = 3 To lr1
    For j = 2 To lrm
    lent = Len(wsm.Cells(j, 1).Value)
    If ws1.Cells(i, 1).Value = Left(wsm.Cells(j, 1).Value, lent - 4) Then
    exist = True
    ws1.Cells(i, 3).Value = "exist"
    ws1.Cells(i, 4).Value = Right(wsm.Cells(j, 1).Value, 3)
    End If
    Next j
    Next i


    i was also wondering if it is possible to add a column to the master list that saves the date the entry was added, it would be nice to see when things were added into the master.

    Thanks again for your help with this.

  10. #10
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Search against separate excel file for existing values, adding next unique identifier

    Here is an update that will place the date next to any added number in the master list.

    As for
    I'm curious whether the lack of 000 formatting could cause a runtime error '5'. The macro was working well, but now can't seem to get past the bolded line below. If stuff in the master file doesn't match this format, would that cause this error?
    Yes, if items in master file don't have the -000 format that error will occur. I will need to see some example data to work out a process to skip those items.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    02-18-2020
    Location
    British Columbia, Canada
    MS-Off Ver
    2015
    Posts
    12

    Re: Search against separate excel file for existing values, adding next unique identifier

    Hello and thanks again,

    The date addition is great, thank you, and this should be a permanent record once the file is saved correct?

    As for the formatting, thanks so much for the offer, however, I removed anything that did not follow the -000 format and it seemed to fix the error. The outliers would generally just be missing one or to of the "place holder" zeros since those entries predate that change. I manually added the leading zeros to those entries in the master list and going forward they should all follow the new format. The other possibility are entries with no unique identifier at the end at all (i.e. NAT1405) but I removed all of these since, if we were to use those particular codes, the macro would just find no entry in the list, add a -001, -002 etc. to the end, and then add those to the list (which would then have the desired format), is that correct?

    The other thing I was wondering about is duplicate values, if the code runs across two of the same value, will it just "treat them as one"? In other words, do we have to be very aware of having a duplicate entry in the master? or can we essentially disregard this? Same goes for gaps in the numbers (sometimes there is a jump where not all the numbers are sequential eg. NAT1405-003 then NAT1405-012), will there be an issue with either of those?

    Thanks so much!
    Last edited by Erbro90; 03-17-2021 at 05:56 PM.

  12. #12
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Search against separate excel file for existing values, adding next unique identifier

    Yes, once file saved then becomes permanent record.

    As for the second paragraph, that is correct.

    You can disregard duplicates and gaps in the numbers, no issue.

  13. #13
    Registered User
    Join Date
    02-18-2020
    Location
    British Columbia, Canada
    MS-Off Ver
    2015
    Posts
    12

    Re: Search against separate excel file for existing values, adding next unique identifier

    That is simply fantastic. So it always goes to the highest number in the list and adds one? That's great, that way I can just add lists without worrying if they have already been put in previously.

  14. #14
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Search against separate excel file for existing values, adding next unique identifier

    I just found in error in the updated code. The sequence numbers weren't incrementing correctly.

    Also, although duplicates and gaps are ok, the product numbers must be sorted with the largest number last, just like the example data. The code looks at the last item and takes the end -### number to then add new ones. So if you add new lists, please sort on product number before running code. The sort can be added into the code if you want.

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    02-18-2020
    Location
    British Columbia, Canada
    MS-Off Ver
    2015
    Posts
    12

    Re: Search against separate excel file for existing values, adding next unique identifier

    Hello,

    Yes an auto sort in the code would be very useful if this is required for the macro to run properly. The date added column should preserve the order of the entries if that is needed in future but I expect to never have to edit this list once the system is set. If you would be so kind as to add this function to the corrected code, I'll update everything and I won't bother you again (hopefully).

    I wonder how I can ever repay you for being so generous with your time and skill?

    Cheers

  16. #16
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Search against separate excel file for existing values, adding next unique identifier

    Here is the code with the sort built in:

    Please Login or Register  to view this content.
    Your thanks and appreciation is all I need.

+ 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. [SOLVED] Create Unique Identifier by either adding or removing a space
    By sherylt13 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-27-2017, 03:31 PM
  2. Replies: 1
    Last Post: 01-29-2015, 04:08 PM
  3. Replies: 4
    Last Post: 06-19-2013, 05:45 AM
  4. Adding Unique Identifier to Rows of data
    By adam_w2009 in forum Excel General
    Replies: 13
    Last Post: 04-21-2013, 06:37 AM
  5. Replies: 3
    Last Post: 07-07-2011, 08:24 PM
  6. Unique File Identifier
    By Jörgen Ahrens in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-05-2005, 10:15 AM
  7. [SOLVED] How do I create a unique identifier # when open excel file?
    By ritarowe in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-28-2005, 02:05 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