Filter option

joy_666

Board Regular
Joined
Dec 10, 2008
Messages
121
Hi,

I am trying to delete records from the sheet using the filter option

I have used the below code

Selection.AutoFilter
Range("B1").Select
Selection.AutoFilter Field:=2, Criteria1:="False"
Rows("42:42").Select
Range("B2").Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp


The above macro deletes the data only if the data starts from row 2 when filtered, the macro deletes only the records starting from row 42....

I used the macro record option ......

How do I deleted all the records when I use a filter option.

In the above case I am filtering the value False and I want to delete all the records under that option......

Kindly suggest.......:)
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi,

Try something like this on a copy of your workbook. It will delete the entire row if FALSE is found in column C. Change Sheet1 for the name of the worksheet you are working on:

Rich (BB code):
Sub foo()
    Dim rngToDelete As Range
 
    With Worksheets("Sheet1")
        .AutoFilterMode = False
 
        With .Range("B1:C1")
            .AutoFilter
            .AutoFilter Field:=2, Criteria1:=False
        End With
 
        With .AutoFilter.Range
            On Error Resume Next
            Set rngToDelete = .Offset(1).Resize(.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible)
            On Error GoTo 0
        End With
 
 
        If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
        .AutoFilterMode = False
 
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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