This is my first post for and my first online programming question.
I am developing a program for recording project applications (Work Orders) at the factory. The current system is being deleted due to a switch from Windows XP.
I had a problem with the development of the numbering code.
Code format: YY - ######. I am currently using:
.Cells(iRow, 1).Value = Format(Date, "yy") & " - " & Format(iRow - 1, "000000")
Thus, to enter Year and "iRow" - 1 in the first column. iRow is defined using:
iRow = 2 'starting index for next empty WONum cell
With WORecordSheet
'Find the next empty WONum cell
Do While .Cells(iRow, 1).Value <> ""
.Cells(iRow, 1).Activate
iRow = iRow + 1
Loop
End With
It scrolls each one until an empty row is found, then enters a number using the year and the specified row minus one in this cell.
The problem I am facing is the year. When the new year arrives, he needs to return to the first work order. For instance:
14 - 001111
14 - 001112
14 - 001113
15 - 000001
15 - 000002
, , . , , 1 , , , , , , , , iRow.
, ... - "YY" "######"? if, "YY" , 1 "######"?
!
UPDATE: , . @user1759942. dim- "Right". :
Dim iRow As Long
Dim yr As Long
Dim lCodeNum As Long
WORecordSheet.Activate
iRow = 2 'starting index for next empty WONum cell
lCodeNum = 1 'starting index for last 6 digits of wonum
With WORecordSheet
'Find the next empty WONum cell
Do While .Cells(iRow, 1).Value <> ""
.Cells(iRow, 1).Activate
iRow = iRow + 1
Loop
yr = Left(.Cells(iRow - 1, 1).Value, 2)
If yr = Format(Date, "yy") Then
lCodeNum = Right(.Cells(iRow - 1, 1).Value, 6) + 1
Else
lCodeNum = 1
End If
End With
:
.Cells(iRow, 1).Value = Format(Date, "yy") & " - " & Format(lCodeNum, "000000")