1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Range, c As Range, s As String, n As Integer, m As Integer
If Not Intersect(Target, Columns("B")) Is Nothing And Target.Count = 1 Then
s = Left(UCase(Target.Value), 1)
If s = "L" Or s = "B" Then
Set r = Range("B1", Cells(Rows.Count, "B").End(xlUp))
For Each c In r.Cells
n = Val(Replace(c.Value, s, "0"))
If n > m Then m = n
Next c
Application.EnableEvents = False
Target.Value = s & Format(m + 1, "000")
Application.EnableEvents = True
End If
End If
End Sub |
Partager