+ Reply to Thread
Results 1 to 8 of 8

Unique number not in order

  1. #1
    Registered User
    Join Date
    07-01-2015
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    51

    Unique number not in order

    Hi, I got this excel file. I wanted to add in new data but recently, I discovered that the unique number (New/2017/xx) is not in order. For example, my last entry unique number is New/2017/49 then when I add in new entry, the unique number will be New/2017/32. Hope someone enlighten me on this. I have attached my file for reference. Thank You

    PS: My original file contained 2000 plus data and it contain my work information. I have replaced it with other data and all the vba macro are the same. Currently, I add in new data, the unique number is in order.
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Unique number not in order

    In UserForm1 code. You will find below line.
    Please Login or Register  to view this content.
    Basically, Counts item in AllNews sheet that meets "News/Year/*" and add that number + 1 as News ID.

    Since ExpiredNews can move from AllNews sheet to ExpiredNews. It will not be unique ID.

    Ex. You had News/2017/1 to News/2017/10 in AllNews. Then moved 1 to 5 to ExpiredNews. Then next item created will have News/2017/6 as ID (which will be duplicate ID).

    As long as you don't move items that are in same year to ExpiredNews. You will have Unique ID generated in order.

  3. #3
    Registered User
    Join Date
    07-01-2015
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    51

    Re: Unique number not in order

    Is there any way which I can moved the expired news but still able to genreate the unique ID

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Unique number not in order

    Yes. Personally I'd leverage "Scripting.Dictionary". By default, Keys for dictionary object needs to be unique.

    For best performance, put all IDs in ExpiredNews into variant array, iterate through and populate dictionary. Do same for AllNews sheet.

    I don't have time tonight to write the code. But will see if I have time tomorrow.
    In the mean time... You can see in link below, how dictionary object was utilized to ensure unique ID (though this one is done on single sheet).
    http://forum.chandoo.org/threads/aut...4/#post-193233

    Edit: If you search with keyword, "Scripting.Dictionary", "VBA" & "Unique ID" you should find plenty of examples.
    Also, alternate approach is to use 12~14 char length numeric string (datetime) concatenated with some string.
    Ex: NEWS-170131211230
    Last edited by CK76; 01-31-2017 at 09:58 PM. Reason: See Edit:

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Unique number not in order

    Actually... come to think of it. It's far easier to count both sheets for same condition and add 1 in this instance.

    No need to introduce additional complexity.

    Changed following section of UserForm module.
    Please Login or Register  to view this content.
    See attached.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-01-2015
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    51

    Re: Unique number not in order

    Hi, thanks, it works. Just to check, if let's say a brand new year start already, will this still works?

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Unique number not in order

    Yes it will. CountIf will return 0 and code adds 1. So new year will start with News/Year/1 always.

  8. #8
    Registered User
    Join Date
    07-01-2015
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    51

    Re: Unique number not in order

    Oh ok. 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. Sum of Order Total Based on Unique Order ID
    By ivdezine in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-31-2015, 07:55 AM
  2. Sum of Order Total Based on Unique Order ID
    By ivdezine in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-31-2015, 07:35 AM
  3. Replies: 5
    Last Post: 07-22-2013, 05:56 PM
  4. VBA to produce a unique and incremented order number in col A
    By lday75 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-26-2013, 02:59 PM
  5. Unique Work Order number generating
    By bobvanderbilt in forum Excel General
    Replies: 0
    Last Post: 08-19-2012, 10:40 PM
  6. Replies: 1
    Last Post: 07-25-2012, 11:05 PM
  7. unique order number according to criteria
    By ellebelle in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-03-2006, 07:35 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