Macro to delete paid items in Col P from row2 onward

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,701
Office Version
  1. 2019
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
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

VBE313

Well-known Member
Joined
Mar 22, 2019
Messages
674
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,776
Office Version
  1. 365
Platform
  1. Windows
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
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,701
Office Version
  1. 2019
Platform
  1. Windows
Thanks for the help guys-code works perfectly
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,776
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,263
Messages
5,595,166
Members
413,973
Latest member
leon1974mk

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