Apenas uma diferença, a atividade e o bairro se forem iguais devem ficar na mesma linha, independente se tem "MAT" ou "TARD".....
Experimente este no lugar do anterior.
Sub ReduzTextoAdicionaValoresV2()
Dim c As Range, k As Long, x As Long, y As Long, w As Long
Dim m As Long, v As Long, LR As Long, fA As String
LR = Cells(Rows.Count, 1).End(3).Row
Range("E2:G" & Range("E2").End(4).Row) = ""
Range("A2:A" & LR).Interior.Color = xlNone
Application.ScreenUpdating = False
For k = 2 To LR
If Cells(k, 1).Interior.ColorIndex <> 40 Then
Cells(k, 1).Interior.ColorIndex = 40
x = InStr(Cells(k, 1), "MAT"): y = InStr(Cells(k, 1), "TARD")
w = Application.Max(x, y)
If w > 0 Then
Set c = Range(Cells(k, 1), Cells(LR, 1)).Find(Left(Cells(k, 1), w - 1), _
Lookat:=xlPart)
If Not c Is Nothing Then
fA = c.Address
Do
If Cells(k, 2) = Cells(c.Row, 2) Then
v = v + Cells(c.Row, 3)
Cells(c.Row, 1).Interior.ColorIndex = 40
End If
Set c = Range(Cells(k, 1), Cells(LR, 1)).FindNext(after:=c)
Loop While Not c Is Nothing And c.Address <> fA
Cells(m + 2, 5) = Left(Cells(c.Row, 1), w - 1)
Cells(m + 2, 6) = Cells(k, 2): Cells(m + 2, 7) = v
m = m + 1: v = 0
End If
End If
End If
Next k
Range("A2:A" & LR).Interior.Color = xlNone
Application.ScreenUpdating = True
End Sub
Postado : 27/07/2016 6:09 pm