Delete Rows 2 Text Strings

Papi

Well-known Member
Joined
May 22, 2007
Messages
1,592
The below works to delete if column P shows "Paid" and column X shows "Final". I suspect there is a better way to write this. Could somebody advise please?

Code:
Sub DeleteTwoDataSets()
    Last = Cells(Rows.Count, "P").End(xlUp).Row
    For i = Last To 1 Step -1
        If (Cells(i, "P").Value) = "Paid" Then
            Cells(i, "P").EntireRow.Delete
        End If
    Next i
   Last = Cells(Rows.Count, "X").End(xlUp).Row
    For i = Last To 1 Step -1
        If (Cells(i, "X").Value) = "Final" Then
            Cells(i, "X").EntireRow.Delete
        End If
    Next i
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try

Code:
Sub DeleteTwoDataSets()
    Last = Cells(Rows.Count, "P").End(xlUp).Row
    For i = Last To 1 Step -1
        If Cells(i, "P").Value = "Paid" And Cells(i, "X").Value = "Final" Then Rows(i).Delete
    Next i
End Sub
 
Upvote 0
Try,

Code:
Sub DeleteTwoDataSets()
With Columns("P")
    .Replace "Paid", "#N/A", xlWhole
    .SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
End With
With Columns("X")
    .Replace "Final", "#N/A", xlWhole
    .SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
End With
End Sub
 
Upvote 0
Papi,

Try the following:

Code:
Sub DeleteTwoDataSets_V2()
' hiker95 , 09/17/2014, ME805971
Dim Last As Long, i As Long
Application.ScreenUpdating = False
Last = Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
For i = Last To 1 Step -1
  If Cells(i, "P").Value = "Paid" Or Cells(i, "X").Value = "Final" Then
    Rows(i).Delete
  End If
Next I
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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