Deleting Autofilter row

SteynBS

Board Regular
Joined
Jun 27, 2022
Messages
104
Office Version
  1. 365
Platform
  1. Windows
Hi Guys. So I am using VBA to AutoFilter a row in a table with conditions. Now I need to delete the entire row. My limited experience with VBA only allows me to select the row and delete, but the row number could change every time.

Sub AutoFilterDelete()


ActiveSheet.ListObjects("VendorCertFrmFile").Range.AutoFilter Field:=2, _
Criteria1:="Appliances Medical Devices Cosmetics"
Rows("157:157").Select (This value will change every time. I need to select the entire row based on the criteria.)
Selection.Delete Shift:=xlUp

End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this

VBA Code:
Sub AutoFilterDelete()
    With ActiveSheet.ListObjects("VendorCertFrmFile").Range
        .AutoFilter 2, "Appliances Medical Devices Cosmetics"
        .Offset(1).EntireRow.Delete
    End With
    
    ActiveSheet.ListObjects("VendorCertFrmFile").AutoFilter.ShowAllData
End Sub
 
Upvote 0
Or this:
VBA Code:
Sub AutoFilterDelete()

Dim loVendor As ListObject
Dim rngDelete As Range

Set loVendor = ActiveSheet.ListObjects("VendorCertFrmFile")

With loVendor
    .Range.AutoFilter Field:=2, Criteria1:="Appliances Medical Devices Cosmetics"
    Set rngDelete = .ListColumns(2).DataBodyRange.SpecialCells(xlCellTypeVisible)
    .AutoFilter.ShowAllData
    rngDelete.Delete Shift:=xlUp
End With

End Sub
 
Upvote 0
Or this:
VBA Code:
Sub AutoFilterDelete()

Dim loVendor As ListObject
Dim rngDelete As Range

Set loVendor = ActiveSheet.ListObjects("VendorCertFrmFile")

With loVendor
    .Range.AutoFilter Field:=2, Criteria1:="Appliances Medical Devices Cosmetics"
    Set rngDelete = .ListColumns(2).DataBodyRange.SpecialCells(xlCellTypeVisible)
    .AutoFilter.ShowAllData
    rngDelete.Delete Shift:=xlUp
End With

End Sub
Thank you
 
Upvote 0
Try this

VBA Code:
Sub AutoFilterDelete()
    With ActiveSheet.ListObjects("VendorCertFrmFile").Range
        .AutoFilter 2, "Appliances Medical Devices Cosmetics"
        .Offset(1).EntireRow.Delete
    End With
   
    ActiveSheet.ListObjects("VendorCertFrmFile").AutoFilter.ShowAllData
End Sub
Thanks
 
Upvote 0

Forum statistics

Threads
1,214,627
Messages
6,120,610
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