Bonjour,
Essayez ceci, la macro réagit au changement de valeur
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Sortie
Application.EnableEvents = False
If Not Intersect(Target, Columns("A:B")) Is Nothing Then
Dim i As Long, k As Long
Réf = Range("B2").Value
Cpt = 0
'on relève tous les chiffres trouvés après le premier caractère alphabétique de la référence en partant de la droite
For i = Len(Réf) To 1 Step -1
If IsNumeric(Mid(Réf, i, 1)) Then
Valeur = Mid(Réf, i, 1) & Valeur
Cpt = Cpt + 1
Else
Exit For
End If
Next
Prefixe = Left(Réf, Len(Réf) - Cpt)
With Feuil1
For i = 3 To .Range("A" & .Rows.Count).End(xlUp).Row
If .Range("A" & i) <> "" Then
If Cells(i, "A") = Cells(i - 1, "A") Then
Cells(i, "B") = Cells(i - 1, "B")
Else
Valeur = (Valeur * 1) + 1
Cells(i, "B") = Prefixe & Valeur
End If
End If
Next i
End With
End If
Sortie:
Application.EnableEvents = True
End Sub
Cdlt