Try this worksheet event.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim temp As Long, LR As Long
LR = Range("C" & Rows.Count).End(xlUp).Row + 1
If Target.Cells.Count = 1 Then
If Target.Column = 2 And Target.Offset(0, 1).Value = "" Then
temp = Target.Value
K = Evaluate("=TEXT(MAX(IF(C3:C" & LR & "<>"""",1*RIGHT(C3:C" & LR & ",5),""""))+1,""00000"")")
Target.Offset(0, 1).Value = "CB-" & Year(temp) & "-" & K
End If
End If
Application.EnableEvents = True
End Sub
Worksheetevent
How to use the code
Right click on Sheet tab --> view code
Visual Basic (VB) window opens.
Paste the code
Close the VB window.
Bookmarks