+ Reply to Thread
Results 1 to 12 of 12

Assign unique project code

  1. #1
    Registered User
    Join Date
    01-15-2015
    Location
    Australia
    MS-Off Ver
    M365
    Posts
    7

    Assign unique project code

    Hi all

    Looking to please understand how I can assign a unique 5 digit project code for each project that we onboard.

    It should be based on a string (eg company name), and if unique id already used, drop off last digit and replace with number chronologically. Where string is less than 5 digits then add number starting with 0 or 00 etc to fill up string.

    Eg, first project is ConstructionTech gets assigned 'const' and second project BuildCo gets 'build', third project Core gets 'core0' If we had Buildalot as a project it should be assigned 'buil1' as it cannot be assigned 'build' as already used,and if we had another project from core it would be 'core1'. When we exhaust these past buil9 it should go to bui01 bui02. This would cater to over 100 variations which would be plenty for the distant future but if it could handle a move to 6 digit code like bui000 that would be a bonus (we would always want 3 letters).

    These shortened codes will be used for complex file management where full company or project names are not feasible. Happy for adjustments to the logic if any thoughts on how to better this concept. We don't want just numbers (like order reference) as some name familiarity is very useful.

    So far I have managed to create the desired 'should-be' code in column B, however what's missing is the validation to verify if the code already exists and edit accordingly which is well beyond my capability unfortunately!

    Thanks so much
    Attached Files Attached Files
    Last edited by bsh3p; 07-06-2021 at 07:14 PM. Reason: Updated attachment

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,958

    Re: Assign unique project code

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,214

    Re: Assign unique project code

    I "assume" you will hold a "central" list of all current project names. What happens if the first 5 characters of two different companies are the same ConstructionTech vs ConstructionWhizzo ?

    See yellow banner above on how to attach a sample workbook.

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Assign unique project code

    Also... are you still using Excel 2007? If not, please update your profile...
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  5. #5
    Registered User
    Join Date
    01-15-2015
    Location
    Australia
    MS-Off Ver
    M365
    Posts
    7

    Re: Assign unique project code

    Hey AliGW

    I've tried to reply but getting the following error:

    The following errors occurred with your submission
    You are not allowed to post any kinds of links, images or videos until you post a few times.

    My reply to John has no links, images or video so not sure what the issue is if you could please assist?

    Cheers, Brendan

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,958

    Re: Assign unique project code

    There must be something in it that the forum software thinks us a link. What were you trying to post?

  7. #7
    Registered User
    Join Date
    01-15-2015
    Location
    Australia
    MS-Off Ver
    M365
    Posts
    7

    Re: Assign unique project code

    Hi John

    I believe I covered this scenario in my initial post however I have attached a sample spreadsheet now which should make more sense.

    Cheers

  8. #8
    Registered User
    Join Date
    01-15-2015
    Location
    Australia
    MS-Off Ver
    M365
    Posts
    7

    Re: Assign unique project code

    Hey Ali

    I'm putting it down to a system glitch, my password suddenly wasn't working either!

    Password reset and managed another reply so we'll just move on :D

  9. #9
    Valued Forum Contributor
    Join Date
    06-23-2021
    Location
    Romania
    MS-Off Ver
    2021, 365 v 2208
    Posts
    722

    Re: Assign unique project code

    Hi,
    The only idea I have in this moment:
    I used a helper column.
    In D2 :
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    and CTRL+SHIFT+ENTER
    in E2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Diana Tanase


    If the solutions offered helped you to solve your problem, then mark the thread as SOLVED (thread tools in the top menu) and you can click on * to add reputation to those who helped you, as a way to say thank you !

  10. #10
    Registered User
    Join Date
    01-15-2015
    Location
    Australia
    MS-Off Ver
    M365
    Posts
    7

    Re: Assign unique project code

    Hi Diana, I appreciate your reply.

    That sort of works but I my testing didn't bring about the output I intended (unless I was perhaps doing something incorrect. I've attached a spreadsheet showing your formulas applied to a list of random company names and the output your formulas brought about vs the expected values.

    This is the formula I've got so far where column A is the company name and column B is the 'should-be' code if the name wasn't already taken. This would work similar to your method where there's a helper column, in my case column A is the company name and column B is the "should be" code that would be the code if not already used.

    =IF(COUNTIF($B$2:$B3,$B4),IF(ISERR(RIGHT(B4,1)*1),LEFT(B4,LEN(B4)-1)&"0",IF(RIGHT(B4,2)="99",LEFT(B4,LEN(B4)-2)&"000",IF(RIGHT(B4,1)="9",LEFT(B4,LEN(B4)-2)&"00",LEFT(B4,LEN(B4)-1)&B4+1))),B4)

    This formula (although not quite working) should in theory:
    1. 1 Look to see if the 5 digit code created in column B has been used already
    2. 2 If it hasn't then use that code - easy!
    3. 3 If the code has already been used then:
    4. If code ends in anything other than a number, drop the last digit and replace with a '0'
    5. If the code ends in '99' then replace last 2 digits with '000'
    6. If code ends in a '9' then replace the last 2 digits with '00'
    7. If code ends in any other number then add 1 to the final number (eg 3 becomes a 4)

    I haven't quite got this code to work but where I've got no idea is how to apply repeatability. The range lookup should repeat such that if the output code is found in the range it provides another ID, and if that ID is found in range, apply another ID and so on.

    Regards, Brendan
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Assign unique project code

    In D2 then copied down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  12. #12
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,214

    Re: Assign unique project code

    Slight mod to Diana's formula:


    =IF(LEN(A2)<5,LEFT(A2,5)&REPT(0,4-LEN(A2))&B2,IF(B2>=1,LEFT(A2,4)&(B2-1),LEFT(A2,5)))


    Change to helper

    =SUMPRODUCT(--(LEFT($A$2:A2,5)=LEFT(A2,5)))-1
    Attached Files Attached Files

+ 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] Extract Unique Data and Assign a Code
    By ionelz in forum Excel General
    Replies: 5
    Last Post: 02-19-2021, 07:49 PM
  2. Assign unique ID to sorted, unique dates
    By Pigeras in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-21-2018, 01:09 PM
  3. When I close another project without macros my macro project still runs its code
    By RossioPS in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2017, 04:07 AM
  4. VBA code to get sum value based on unique project value.
    By Ishwarind in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-06-2016, 11:31 AM
  5. Assign unique ID IF adjacent cell has unique value
    By attaboy000 in forum Excel General
    Replies: 1
    Last Post: 06-05-2014, 02:17 PM
  6. [SOLVED] Function that concatenates multiple sub-project descriptions based on project code
    By markbpi in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-28-2012, 06:49 PM
  7. If i entered any project code in sheet2 display all data of that project
    By koolguys4u in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-21-2009, 03:09 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