PDA

View Full Version : Delete Rows that meet a Criteria



Michael1974
07-01-2015, 07:01 AM
Hello,

Please see the attached spreadsheet. I am trying to get a code to delete all rows that have the word "PDM" alone.

Thanks

SamT
07-01-2015, 11:21 AM
BTW, the word is "PDM "

Sub PDM_DeleteLoneRows()
'For help see: http://www.vbaexpress.com/forum/showthread.php?53069-Delete-Rows-that-meet-a-Criteria
Dim Rw As Long
Dim WsF As Object
Set WsF = Application.WorksheetFunction

Rw = Cells(Rows.Count, "I").Row
With Columns("I")
Do
If Replace(.Cells(Rw).Value, " ", "") = "PDM" And WsF.CountA(Rows(Rw)) = 1 Then Rows(Rw).Delete
Rw = Rw - 1
Loop While Rw > 0
End With
End Sub