Search code examples
excelvbafilterworksheet

After filtering, how to select and remove visible rows in Excel?


ActiveSheet.Range("$A$1:$O$1464").AutoFilter Field:=7, Criteria1:="promo"
ActiveSheet.Range("$A$1:$O$1464").AutoFilter Field:=12, Criteria1:="="
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

I would like to select the visible rows after filtering. I read up some post which uses .SpecialCells(xlCellTypeVisible) but I not sure how to amend my existing code.


Solution

  • You can do it this way (after filtering):

    ' Update: don't select the header
    Activesheet.Range("$A$2:$O$1464").SpecialCells(xlCellTypeVisible).Select
    Selection.EntireRow.Delete