Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then Call Trier: Call numeroter
End Sub
Sub Trier()
Dim LastRow As Long
LastRow = ActiveSheet.Range("B18").End(xlDown).Row
Range("B18:C" & LastRow).Sort Key1:=Range("B18"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
End Sub
Sub numeroter()
Dim LastRow As Long, i As Long
LastRow = Range("B18").End(xlDown).Row
Range("a18:a" & LastRow).FormulaR1C1 = "=SUM(R[-1]C,RC[1]<>R[-1]C[1])"
Range("a18:a" & LastRow) = Range("a18:b" & LastRow).Value
End Sub