Macro to delete paid items in Col P from row2 onward

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have headers in row1 on sheet6

want to delete all rows from row2 onwards where 'Paid' appears in Col P

I have written code to do this, but the headers in row1 are also deleted


It would be appreciated if someone could kindly amend my code so that row1 in not deleted



Code:
 Sub DeletePaidItems()

With Sheets(6).Cells(2).CurrentRegion.Columns(16)

.AutoFilter 1, "Paid"

.EntireRow.Delete

End With

End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
VBA Code:
Sub DeletePaidItems()
Dim cl As Object, lastRow As Long
Application.ScreenUpdating = False
With Sheets(6)
    lastRow = .Cells(.Rows.Count, 16).End(xlUp).Row
    For Each cl In .Range("P2:P" & lastRow)
        If cl.Value = "Paid" Then cl.EntireRow.Delete
    Next cl
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
How about
VBA Code:
Sub howard()
   With Sheets(6)
      .Range("A1:P1").AutoFilter 16, "Paid"
      .AutoFilter.Range.Offset(1).EntireRow.Delete
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
Thanks for the help guys-code works perfectly
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,628
Messages
6,120,618
Members
448,973
Latest member
ChristineC

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