Hello mjwillyone,
Here is another version that matches "Name:" anywhere in the cell and isn't case sensitive. More code than Rylo's, but a bit more robust if you need it. For all the code, it is still very quick.
Sub DeleteNonMatchingRows()
Dim Col As Variant
Dim DelRng As Range
Dim LastRow As Long
Dim FirstAddx As String
Dim SrchCell As Range
Dim SrchRng As Range
Dim SrchValue As Variant
Dim StartRow As Long
Col = "H"
StartRow = 2
SrchValue = "Name:"
LastRow = Cells(Rows.Count, "H").End(xlUp).Row
LastRow = IIf(LastRow < StartRow, StartRow, LastRow)
Set SrchRng = Range(Cells(StartRow, Col), Cells(LastRow, Col))
Set SrchCell = SrchRng.Find(What:=SrchValue, After:=SrchRng.Cells(1, 1), _
LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not SrchCell Is Nothing Then
FirstAddx = SrchCell.Address
Set DelRng = SrchCell
Do
Set DelRng = Union(DelRng, SrchCell)
Set SrchCell = SrchRng.FindNext(SrchCell)
Loop While Not SrchCell Is Nothing And SrchCell.Address <> FirstAddx
End If
For R = SrchRng.Rows.Count + StartRow - 1 To StartRow Step -1
If Intersect(SrchRng.Cells(R, 1), DelRng) Is Nothing Then
SrchRng.Cells(R, 1).EntireRow.Delete Shift:=xlShiftUp
End If
Next R
End Sub
Sincerely,
Leith Ross
Bookmarks