+ Reply to Thread
Results 1 to 4 of 4

Append dynamic number to a cell

  1. #1
    Registered User
    Join Date
    08-06-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Append dynamic number to a cell

    I'm create a unique id for our customer by using first 4 letters of the customer name, and then auto-assigning a 4 digit number after that. I've got the first part down, but I'm kinda stumped when it comes to the dynamic number assignment. The idea is that I would like to assign a 4 digit number after the 4 letters, starting with 0001, and increasing by one if the cell already exists. Here is an example of what I would like to do.

    Customer
    20th Century
    Time Warner
    Time Magazine
    Timex
    Zoo Productions

    CustomerID:
    20TH0001
    TIME0001
    TIME0002
    TIME0003
    ZOOP0001

    Hope someone can help with this. I've got 7500 rows of data, really don't want to do this by hand.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Append dynamic number to a cell

    Based on that, assuming the customer name is column A, then this formula in column B, then copied down:

    =UPPER(LEFT($A2,4) & TEXT(COUNTIF($A$2:$A2,LEFT($A2,4)&"*"), "0000"))


    Afterwards, copy column B, then do a PASTE SPECIAL > VALUES to remove the formulas and leave the codes behind.


    EDIT: Use Jason's version below, it covered the spaces which I forgot.
    Last edited by JBeaucaire; 08-07-2012 at 04:12 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Append dynamic number to a cell

    Sorry Jerry I didn't realize you'd replied.

    Your solution seems better so I've removed mine.

    DBY
    Last edited by DBY; 08-07-2012 at 03:35 PM. Reason: Better solution already submitted

  4. #4
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Append dynamic number to a cell

    Allowing for spaces in the first 4 characters of the customer name

    =UPPER(LEFT(SUBSTITUTE(A2," ",""),4))&TEXT(1+COUNTIF(B$1:B1,LEFT(SUBSTITUTE(A2," ",""),4)&"*"), "0000")

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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