Private Sub Worksheet_Change(ByVal Target As Range)
Dim ltr$, ind%, col, MInd, oCel As Range, x As Object
col = "C" 'Colonne des identifiants (1 ou "A", 2 ou "B", …, 28 ou "AB", …)
With [B8] 'Première cellule de saisie
col = colNum(col) - .Column
Set x = Intersect(.Resize(Rows.Count - .Row, 1), Target)
If Not x Is Nothing Then
Application.Calculation = -4135
On Error GoTo DefRef
MInd = Evaluate(ThisWorkbook.Names("MaxIndex").Value)
On Error GoTo 0
For Each oCel In x.Cells
If IsEmpty(oCel) And oCel.Offset(0, col).Value = MInd Then
MInd = MInd - 1
Application.EnableEvents = 0
oCel.Offset(0, col).Value = ""
Application.EnableEvents = 1
ElseIf oCel.Offset(0, col).Value = "" Then
MInd = MInd + 1
Application.EnableEvents = 0
oCel.Offset(0, col).Value = MInd
Application.EnableEvents = 1
End If
Next oCel
ThisWorkbook.Names.Add Name:="MaxIndex", RefersTo:=MInd
Application.Calculation = -4105
End If
End With
Exit Sub
' Initialisation
DefRef:
rst
Resume
End Sub