Greetings,
I'm grateful for finding the Worksheet Change code below on this forum. After a small modification per my needs, it successfully generates a unique ID in column AB whenever a new record is entered in column A. I would like to modify the code so that the current year and a hyphen always precede the unique ID. E.g., the first record in 2018 would be 2018-1; the next would be 2018-2; etc. Then the first record to be entered in 2019 would be 2019-1, and so on. I’ve attempted to modify the code, as well as find the solution on the forum, but to no avail so far. Any suggestions would be greatly appreciated -thank you.
I'm grateful for finding the Worksheet Change code below on this forum. After a small modification per my needs, it successfully generates a unique ID in column AB whenever a new record is entered in column A. I would like to modify the code so that the current year and a hyphen always precede the unique ID. E.g., the first record in 2018 would be 2018-1; the next would be 2018-2; etc. Then the first record to be entered in 2019 would be 2019-1, and so on. I’ve attempted to modify the code, as well as find the solution on the forum, but to no avail so far. Any suggestions would be greatly appreciated -thank you.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim maxNumber
If Not Intersect(Target, Range("A:A")) Is Nothing Then
If Target.Rows.Count > 1 Then Exit Sub
If Cells(Target.Row, 27) > 0 Then Exit Sub
maxNumber = Application.WorksheetFunction.Max(Range("AB:AB"))
Target.Offset(0, 27) = maxNumber + 1
End If
End Sub