Sub Exemplo()
Dim lRow As Long
Dim lContador As Long
Dim lPadrão As Long
lPadrão = -999
For lRow = 1 To RowLast(Columns("B"))
If Cells(lRow, "B") = lPadrão Then
lContador = lContador + 1
Else
lContador = 1
lPadrão = Cells(lRow, "B")
End If
Cells(lRow, "A") = lContador
Next lRow
End Sub
Function RowLast(rng As Range) As Long
'Retorna o valor da última linha povoada da coluna rng
With rng
On Error Resume Next
RowLast = .Find(What:="*" _
, After:=.Cells(1) _
, SearchDirection:=xlPrevious _
, SearchOrder:=xlByColumns _
, LookIn:=xlFormulas).Row
If RowLast = 0 Then RowLast = rng.Cells(1).Row
End With
End Function
Felipe Costa Gualberto - http://www.ambienteoffice.com.br