Delete entire row if it contains a specific word

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If you need to use a macro, maybe like this
Code:
Sub deleterows()
    Dim I As Integer
    For I = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
        If WorksheetFunction.CountIf(Rows(I).EntireRow, "p6") > 0 Then
            Rows(I).EntireRow.Delete
        End If
    Next I
End Sub
 
Upvote 0
Or perhaps:
Code:
Sub DeleteRowsContainingP6()
        
    Dim MyRange As Range
    Dim MyTotal As Long
    
    Set MyRange = Range("A1:C200")
    MyTotal = MyRange.Cells.Count
    
    For MyCount = MyTotal To 1 Step -1
        If InStr(1, MyRange.Cells(MyCount).Formula, "P6") <> 0 Then
        MyRange.Cells(MyCount).EntireRow.Delete
        End If
    Next
    
End Sub

This will work for cells that CONTAIN "P6" as well as equalling it - just alter the MyRange reference to suit your needs.

Hope this helps

Pete
 
Upvote 0
Or perhaps:
Code:
Sub DeleteRowsContainingP6()
        
    Dim MyRange As Range
    Dim MyTotal As Long
    
    Set MyRange = Range("A1:C200")
    MyTotal = MyRange.Cells.Count
    
    For MyCount = MyTotal To 1 Step -1
        If InStr(1, MyRange.Cells(MyCount).Formula, "P6") <> 0 Then
        MyRange.Cells(MyCount).EntireRow.Delete
        End If
    Next
    
End Sub

thanks man worked a treat.
 
Upvote 0
Thanks for that, Momentman. I'm still having fun with your MouseUp/MouseDown solution from the other week!

Pete
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top