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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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

vds1

Well-known Member
Joined
Oct 5, 2011
Messages
1,200
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

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
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,190,916
Messages
5,983,567
Members
439,849
Latest member
Tlaw

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
Top