I have a filter macro that will filter a table for items and delete rows with that item. This is done by looping through an array which referenced a finite range on reference worksheet.
I am trying to change this array to be dynamic so that I can add or remove items to be deleted without having to open the code.
Before:
Dim ArrCategory As Variant
ArrCategory = Worksheets("Sheet1").Range("B8:B12")
For i = 2 To LastRowA
For Each item In ArrCategory
If Range("E" & i).Value = item Then
lo1710.Range.autofilter Field:=5, Criteria1:=item
Application.DisplayAlerts = False
lo1710.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True
lo1710.autofilter.ShowAllData
Else
End If
Next item
Next i
After:
Dim ArrCategory As Variant
ArrCategory = Worksheets("Sheet1").Range("B8:B" & Cells(Rows.Count, "B").End(xlUp).row)
For i = 2 To LastRowA
For Each item In ArrCategory
If Range("E" & i).Value = item Then
lo1710.Range.autofilter Field:=5, Criteria1:=item
Application.DisplayAlerts = False
lo1710.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True
lo1710.autofilter.ShowAllData
Else
End If
Next item
Next i
After making this change I started getting the "No cells were found" error. When I look in the locals window to see what is in that array, I see the values that are supposed to be in there, but then also hundreds of "empties".
The code does work to eliminate the rows containing the items in the array.
