Deleting Rows that meet filtered criteria only in a table

XCaliber

New Member
Joined
Jan 16, 2014
Messages
41
Hi

If I filter a table and the filtered result is what needs to be deleted (nothing else), How do i go about writing code to select the filtered rows to be deleted only (not the headers) within the Table or the rest of the worksheet?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
here is a sample that does that. Filters on column R


Code:
    Cells.AutoFilter Field:=18, Criteria1:="0"
    LR = ActiveSheet.Range("R" & Rows.Count).End(xlUp).Row
    Range("R2:R" & LR).SpecialCells(xlCellTypeVisible).Select
    Range("R2:R" & LR).Delete
    Cells.AutoFilter
 
Upvote 0
here is a sample that does that. Filters on column R


Code:
    Cells.AutoFilter Field:=18, Criteria1:="0"
    LR = ActiveSheet.Range("R" & Rows.Count).End(xlUp).Row
    Range("R2:R" & LR).SpecialCells(xlCellTypeVisible).Select
    Range("R2:R" & LR).Delete
    Cells.AutoFilter

So This code is a little greek to me, but tell me if I am on the right track with it. Am I to understand that this code basically begins selection of rows from the bottom to the top of the table? If so, that's brilliant.
 
Upvote 0
Assuming you want to delete any row that has "Dad" in column "R" use this script.

Modify to your needs.

Code:
Sub FilterMini()
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "R").End(xlUp).Row
With Range("R2:R" & Lastrow)
.AutoFilter Field:=1, Criteria1:="Dad", Operator:=xlFilterValues
.SpecialCells(xlCellTypeVisible).Rows.Delete
End With
ActiveSheet.AutoFilterMode = False
End Sub
 
Upvote 0
So This code is a little greek to me, but tell me if I am on the right track with it. Am I to understand that this code basically begins selection of rows from the bottom to the top of the table? If so, that's brilliant.
This uses a filter for the selection and then deletes those rows
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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