jfitzsimmons
New Member
- Joined
- Jun 11, 2019
- Messages
- 1
Basically im trying to filter a large set of data. I have people's names and want to delete all rows not containing these names. I used this macro originally:
Sub DeleteRows()
Dim Cell As Range, cRange As Range, LastRow As Long, x As Long
LastRow = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row
Set cRange = Range("C2:C" & LastRow)
For x = cRange.Cells.Count To 1 Step -1
With cRange.Cells(x)
If .Value <> "john smith" And .Value <> "jane doe" Then
.EntireRow.Delete
End If
End With
Next x
End Sub
The problem was, some of the names also included middle initial or some difference. Is there a way to make this not specific. so if I put If .Value <> "John Smith" it can keep all cells containing that, not equaling that?
Sub DeleteRows()
Dim Cell As Range, cRange As Range, LastRow As Long, x As Long
LastRow = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row
Set cRange = Range("C2:C" & LastRow)
For x = cRange.Cells.Count To 1 Step -1
With cRange.Cells(x)
If .Value <> "john smith" And .Value <> "jane doe" Then
.EntireRow.Delete
End If
End With
Next x
End Sub
The problem was, some of the names also included middle initial or some difference. Is there a way to make this not specific. so if I put If .Value <> "John Smith" it can keep all cells containing that, not equaling that?