Conditional Row Deletion
You want AND instead of OR
Sub RowDelete()
Dim i As Long
Dim iLastRow As Long
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 2 Step -1
If Not(Cells(i, "D").Value Like "MN*") AND _
Not(Cells(i, "D").Value Like "MP107*") Then
Rows(i).Delete
End If
Next i
End Sub
or
Sub RowDelete()
Dim i As Long
Dim iLastRow As Long
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 2 Step -1
If Not(Cells(i, "D").Value Like "MN*" Or _
Cells(i, "D").Value Like "MP107*") Then
Rows(i).Delete
End If
Next i
End Sub
--
Regards,
Tom Ogilvy
"Kirk P." wrote in message
...
I'm having trouble with this code:
Sub RowDelete()
Dim i As Long
Dim iLastRow As Long
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 2 Step -1
If Cells(i, "D").Value < "MN*" Or Cells(i, "D").Value < "MP107*" Then
Rows(i).Delete
End If
Next i
End Sub
I'm trying to delete all rows where the text contained in column D DOES
NOT
equal MN or MP107. When I run this procedure, it deletes ALL rows. Help!
|