I have a function in vba that loops through a set of data and checks if certain values exist and if they do, delete the row. It works but it doesn't delete all the values. I'm pretty sure it is because the loop's upper bound is the row count of the range which with every deletion, gets smaller. How would I change this? Any help would be greatly appreciated!
Function DeleteClients(rng1 As Range, rng2 As Range)
vData1 = rng1.Value
For i = 1 To rng2.Rows.Count
For j = LBound(vData1, 1) To UBound(vData1, 1)
If rng2.Cells(i, 1).Value = vData1(j, 1) Then
rng2.Cells(i, 1).EntireRow.Delete
Exit For
End If
Next j
Application.StatusBar = "Deleting out excluded clients... " & i & "/" & rng2.Rows.Count & " Records Processed " & Round((i / rng2.Rows.Count) * 100, 0) & " % Complete"
Next i
Application.StatusBar = False
End Function