+ Reply to Thread
Results 1 to 7 of 7

Thread: Batch Number Generator

  1. #1
    Registered User
    Join Date
    10-16-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2003, 2010
    Posts
    60

    Batch Number Generator

    Greetings All,

    I am trying to create a worksheet to generate batch codes in the form: YMM999, using a single digit for the year, a 2 digit month, and a serial number for the actual batch number. What I would like is to be able to enter the current date, and have the year and month extracted, comparing the month to the month from the previous entry and either increasing the serial counter by one, or resetting it to 1 if the month has changed.

    I don't have a problem doing the comparison, padding the serial number portion of the batch number with zeros, or getting it to sequence. I just keep running into a mental block trying to get the year into a form to be compared. I can use =MONTH() to get the 1-12 month value from a date, but I am not getting good years using the =YEAR() function.

    I probably have blinders on, but I just don't see a way to get the year out of the date.

    I will appreciate any input. Thanks.
    Last edited by jacob@thepenpoint; 12-29-2011 at 10:44 AM. Reason: Solved
    Jacob Albers
    Excel 2003 & 2010

  2. #2
    Valued Forum Contributor
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    1,957

    Re: Batch Number Generator

    Are you trying to do this using a macro or formula? If formula then where are you getting the current date from?

  3. #3
    Registered User
    Join Date
    10-16-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2003, 2010
    Posts
    60

    Re: Batch Number Generator

    I am trying to do it using a formula, the user would input the date, and the formula would calculate off of that. It would be creating a table with searchable data as I would add the product and size being made under that particular batch number.
    Jacob Albers
    Excel 2003 & 2010

  4. #4
    Valued Forum Contributor
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    1,957

    Re: Batch Number Generator

    OK, assuming your date is going to be in column A and the batch number is in column B then I'd go with something like this, starting at row 2

    =IF(OR(A2="",ISERROR(MONTH(A2))),"",RIGHT(YEAR(A2),1) & TEXT(MONTH(A2),"00") & TEXT(IF(OR(LEN(B1)<3,ISERROR(VALUE(B1))),1,IF(MONTH(A2)=VALUE(MID(B1,2,2)),VALUE(RIGHT(B1,3))+1,1)), "000"))

    That can then be copied down for as many rows as you want, but will remain blank until a valid date is entered in column A for each row.

  5. #5
    Registered User
    Join Date
    10-16-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2003, 2010
    Posts
    60

    Re: Batch Number Generator

    Brilliant! Thanks! I had everything working except getting the year portion, but it was in a very convoluted formula with helper columns and all kinds of fun stuff. Your solution works perfectly and keeps it all in a nice, neat cell without the need for helper columns.

    Thanks
    Jacob Albers
    Excel 2003 & 2010

  6. #6
    Valued Forum Contributor Haseeb A's Avatar
    Join Date
    05-24-2011
    Location
    India | Kwt
    MS-Off Ver
    2007
    Posts
    1,453

    Re: Batch Number Generator

    Also: B2, copy down.

    =IF(A2="","",RIGHT(TEXT(A2,"yymm"),3)&TEXT(COUNTIF(B$1:B1,RIGHT(TEXT(A2,"yymm"),3)&"*")+1,"000"))
    HTH; Haseeb

    If your problem is solved, please say so clearly, and mark your thread as Solved:
    Forum Rules & How to Mark a thread as SOLVED

  7. #7
    Registered User
    Join Date
    10-16-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2003, 2010
    Posts
    60

    Re: Batch Number Generator

    Quote Originally Posted by Haseeb A View Post
    Also: B2, copy down.

    =IF(A2="","",RIGHT(TEXT(A2,"yymm"),3)&TEXT(COUNTIF(B$1:B1,RIGHT(TEXT(A2,"yymm"),3)&"*")+1,"000"))
    This works great too. I don't quite understand the logic yet, but I'm working through it.

    Thanks!
    Jacob Albers
    Excel 2003 & 2010

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0