I am somewhat novice to VBA. I have a column of around 500 names. In another sheet I have a shorter column of names all found within the longer.
I am trying to loop through the longer column and delete all the rows where the cell value is not found within the shorter. My code works but only deletes rows in increments and needs to be run about 10 times to complete the task.
I know loops involving deletion can be tricky. Any help would be appreciated!
Sub FindMatches()
Application.ScreenUpdating = False
Dim var As Variant, iSheet As Integer, iRow As Long, iRowL As Long, bln As Boolean
iRowL = Cells(Rows.Count, 1).End(xlUp).Row
For iRow = 1 To iRowL
If Not IsEmpty(Cells(iRow, 1)) Then
For iSheet = ActiveSheet.Index + 1 To Worksheets.Count
bln = False
var = Application.Match(Cells(iRow, 1).Value, Worksheets(iSheet).Columns(1), 0)
If Not IsError(var) Then
bln = True
Exit For
End If
Next iSheet
End If
If bln = False Then
Cells(iRow, 1).EntireRow.Delete
Else
Cells(iRow, 1).Font.Bold = True
End If
Next iRow
Application.ScreenUpdating = True
End Sub