I am trying to delete rows in a table on an excel sheet with multiple tables based on the values in each row. After much research and trial and error, I have gotten my macro to work except I have to run it multiple times to actually delete all of the "bad" rows. Here's what I have so far:
Sub RemovePartsOfTable()
Dim row As Range
For Each row In ListObjects("Table6").DataBodyRange.Rows
If row.Columns(6).Value = "" Then 'to exit when it hits the end of the used cells
Exit For
ElseIf row.Columns(1).Value <> "P" And row.Columns(1).Value <> "B" _
And row.Columns(2).Value <> "B" _
And row.Columns(2).Value <> "P" Then
row.Delete
End If
Next
End Sub
The macro does delete all of the rows that I don't want in the table if I run it five times, but I would rather not have to run it more than once since I'm building this workbook for someone else to use too.