Deleting rows if column contains...

Foz1980

Board Regular
Joined
May 6, 2015
Messages
128
Hi all,

My VBA skills are very limited. I have found the below code from another thread which I've copied and pasted into my coding, it has worked for me to a point.
This currently deletes any rows where column T contains the phrase "Pending Failure". But I need to go a step further and it delete any rows where column T contains either "Pending Failure" or "Variation".

Code:
    Dim MyCol As String
    Dim i As Integer
    For i = 1 To Range("T" & "65536").End(xlUp).Row Step 1
    If Application.WorksheetFunction.CountIf(Range("A" & i & ":AZ" & i), "Pending Failure") > 0 Then
    Range("T" & i).EntireRow.Delete
    End If
    Next i

Please can someone help?

Cheers

Chris
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try:

Code:
Dim MyCol As String
    Dim i As Integer
    For i = 1 To Range("T" & "65536").End(xlUp).Row Step 1
    If application.sum(Application.CountIf(Range("A" & i & ":AZ" & i), array("Pending Failure","Variation"))) > 0 Then
    Range("T" & i).EntireRow.Delete
    End If
    Next i
 
Upvote 0
Another option
Code:
Sub FltrDel()

   With ActiveSheet
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("T:T").AutoFilter 1, "*Pending Failure*", xlOr, "*Variation*"
      .UsedRange.Offset(1).SpecialCells(xlVisible).EntireRow.Delete
      .AutoFilterMode = False
   End With
      
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Hi all,

I have used the following code and it deletes all but one row that contains "Pending Failure" - can anyone tell me where I have gone wrong?

Code:
    Dim MyCol As String
    Dim i As Integer
    For i = 1 To Range("T" & "65536").End(xlUp).Row Step 1
    If Application.Sum(Application.CountIf(Range("A" & i & ":AZ" & i), Array("Pending Failure", "Variation"))) > 0 Then
    Range("T" & i).EntireRow.Delete
    End If
    Next i

Cheers

Chris
 
Upvote 0
When deleting rows in a loop you should always loop from bottom to top.
try
Code:
For i = Range("T" & Rows.Count).End(xlUp).Row To 2 Step -1
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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