You could use iterative calculation option in excel, but I'm not a big fan of this and for me the task seems to be well suited to use a Worksheet_change event handler.
Try inserting such code in your worksheet code - not standard module (so right-click on sheet name tab and ->show code):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim mycell As Range
If Not Intersect(Target, Columns(2)) Is Nothing Then
For Each mycell In Intersect(Target, Columns(2))
If mycell.Value = mycell.Offset(0, -1).Value Then
mycell.Offset(0, 1).Value = mycell.Offset(0, 1).Value + 1
Else
mycell.Offset(0, 1).Value = 0
mycell.Offset(0, -1).Value = mycell.Value
End If
Next mycell
End If
End Sub
Remember to save your workbook in macro-containing format like xlsm or xls
The code above is for the data in columns A and B (previous and current) and counter in C. Instead of Columns(2) in real life it's probably better to use Range("B2:B10") or similar (it appears twice in above code).