Set serial number base on date and starting

Solved/Closed
sam - Jul 2, 2012 at 05:36 AM
 sam - Jul 13, 2012 at 02:50 AM
Hello,

I have a local purchase order (LPO) sheet in excel for two different group. I use LPO serial as
SWM/SB/12/07/125
Swm/SB is permanent term
12/07 is the current year and month
125 is the current LPO next One would be 126

What i really want is one i print this form serial number need to change as
SWM/SB/12/07/126 (125 change 126 after print)

Please help ..urgent


Related:

2 responses

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Jul 3, 2012 at 10:30 AM
Hi Sam,

Assuming your LPO serial is in cell A1, otherwise change the reference in the code. Implement the following code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim FP As String
Dim SP As Integer

Application.EnableEvents = False
Cancel = True
     
ActiveWindow.SelectedSheets.PrintOut Copies:=1
     
FP = Left(Range("A1"), 13)
SP = Right(Range("A1"), 3)
Range("A1").Value = FP & SP + 1
     
Application.EnableEvents = True
End Sub

Code needs to be pasted under ThisWorkbook.
Now give the print order and see if the result is the right one.

Best regards,
Trowa
0
Hi Trowa,
Thanks a million for your support. I did as you said. but it didn't work out. I'm not expert in this. Do i have to type SWM/SB/12/07/125 in A1 Cell or only SWM/SB/ because I need your VB extract month and day from system. Please let me know.
Thanks a lot again for ur help
Sam
0
Dear Trow,

Thanks it's working properly.
0
Dear Trowa,

I need Year and Month automatically pick in system. pls help.
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Jul 10, 2012 at 10:27 AM
Hi Sam,

To get the year and month automatically try this formula:
="SWM/SB/"&YEAR(TODAY())-2000&"/"&IF(MONTH(TODAY())<10;"0"&MONTH(TODAY());MONTH(TODAY()))&"/125"

Just to be clear, this formula can be placed in any cell. Just make sure the cell reference in the code (3x A1) is the same as the cell you chose to put the formula in.

Best regards,
Trowa
0
Hi,
Thanks a lot but it doesn't work
="SWM/SB/"&YEAR(TODAY())-2000&"/"&IF(MONTH(TODAY())<10;"0"&MONTH(TODAY());MONTH(TODAY()))&"/125"
excel shows error highlights near "0"
Pls help
Regards
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Jul 12, 2012 at 09:31 AM
Hi Sam,

Could it be because I forgot to replace ; with ,?

Regards
0
Dear TrowaD,

It's working. thanks a lot. you have being a great help for me. have a nice day to you.
0