If you go out of your way and code it as inefficient as you can (many loops), it still is fast enough.
Sub Maybe()
Dim k As Long, a() As String, i As Long, x As String, j As Long, c As Range, y As Double
Application.ScreenUpdating = False
k = 1
ReDim a(1 To k)
a(1) = Cells(20, 7).Value
i = 21
While Not IsEmpty(Cells(i, 7))
x = Cells(i, 7).Value
If IsError(Application.Match(x, a, 0)) Then
k = k + 1
ReDim Preserve a(1 To k)
a(k) = x
End If
i = i + 1
Wend
For j = LBound(a) To UBound(a)
y = 0
For Each c In Range("G20:G" & Cells(Rows.Count, "G").End(xlUp).Row)
If c.Value = a(j) Then y = y + c.Offset(, -4).Value
Next c
If y = 0 Then
For Each c In Range("G20:G" & Cells(Rows.Count, "G").End(xlUp).Row)
If c.Value = a(j) Then c.Offset(, -6).Resize(, 7).ClearContents
Next c
Else
Cells(Rows.Count, "P").End(xlUp).Offset(1).Value = y
End If
Next j
Application.ScreenUpdating = True
End Sub
Bookmarks