My data is like follows:
Name Value Flag
Alice 5 BUYBACK
Bob 8 Jump
Dan 9
Alice 1
Alice 6 Jump
Dan 0 BUYBACK
Bob 8 Jump
If for any Name, in any record, in the Flag field if there is a "BUYBACK" then I want to preserve all the records associated with that name. Alice has 3 records and one of them is BUYBACK so I want to keep all of ALice's records. Dan has a buy back in one of the two so I want to keep both of Dan's records while both of Bob's records get deleted.
When I try to do it below, I get an error in my AutoFilter. The error says "Object required". I can't seem to figure out what's wrong.
n = 1
Dim BBK_Array() As Variant
For j = 1 To FinalRow
If Cells(j, 3).Value = "BUYBACK" Then
If n = 1 Then
ReDim Preserve BBK_Array(1 To n)
BBK_Array(n) = Cells(j, 1).Value
n = n + 1
ElseIf BBK_Array(n - 1) <> Cells(j, 1).Value Then
ReDim Preserve BBK_Array(1 To n)
BBK_Array(n) = Cells(j, 1).Value
n = n + 1
End If
End If
Next j
ActiveWorksheet.UsedRange.AutoFilter Field:=1, Criteria1:=BBK_Array(), Operator:=xlFilterValues
EDIT:
When I did this, it worked. I don't know why:
ActiveWorkbook.Activesheet.UsedRange.AutoFilter Field:=1, Criteria1:=BBK_Array(), Operator:=xlFilterValues



