Serial number with last 4 digits resetting every year.

Nesha

New Member
Joined
Feb 4, 2015
Messages
3
Hi
I currently have a great macro that, when a "generate" button is pressed, it puts out a serial number in the format of YYMMXXXX (where XXXX begins from 0001) and populates the next available row with this number. However we now need it to reset the last four digits to go back to 0001 every time a new year has begun.
The year and month are automatically input from "today's" date.
Having a little trouble trying to tweak this so that the numbers reset :/
Any help will be greatly appreciated ☺
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi, Sorry...posted the question from my phone last night. Here's the macro:


Sheets("Do Not Modify").Select
SerialNo = ThisWorkbook.Worksheets(2).Cells(1, 1)
ThisWorkbook.Worksheets(2).Cells(1, 1) = SerialNo+ 1
Range("B13").Select
Selection.Copy
Sheets("Serial Number Generator").Select
Range("I4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("F7").Select
ThisWorkbook.Save
Range("I4").Copy
lMaxRows = Cells(Rows.Count, "B").End(xlUp).Row
Range("B" & lMaxRows + 1).Select
Selection.PasteSpecial Paste:=xlPasteAll


Thank-you
 
Upvote 0
253
5/02/2015 =TODAY()
15 =YEAR(B2)-2000
02 =TEXT(B2,"mm")
253 =A1
SERIAL:
S-15020253 =CONCATENATE("S","-",A4,B4,(IF(B5<10,"000",IF(B5<100,"00",IF(B5<1000,"0",)))),B5)

<tbody>
</tbody>
(Couldn't paste the screenshot - but for demonstration purposes the Serial No is supposed to be output into B13 - not the 6th row down)
A1 is the cell that is referred to in the beginning of the macro- its the number that changes and that I want to go back to 1 when a new year starts.

Hopefully it makes a little more sense now...let me know if any more information is needed
 
Upvote 0
Maybe try:

Code:
    SerialNo = ThisWorkbook.Worksheets(2).Cells(1, 1)
    If Mid(Sheets("Serial Number Generator").Range("I4").Value, 3, 2) = Format(Date, "yy") Then
        ThisWorkbook.Worksheets(2).Cells(1, 1) = SerialNo + 1
    Else
        ThisWorkbook.Worksheets(2).Cells(1, 1) = 1
    End If
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,428
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top