- filter and delete rows in excel
- excel vba delete filtered rows but not header
- vba delete visible rows except header
- vba code to delete rows based on criteria
- excel vba delete filtered rows in table
Dim i, j As Long
j = Cells(Rows.Count, "A").End(xlUp).Row
Sheets("Sheet1").Range("A1").Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=IF(ISERROR(MATCH(""ABC"",C8:C8,0)),0,1)"
i = ActiveCell.Value
ActiveCell.Value = i
Selection.ClearContents
If i > 0 Then
Range("$A$1:$Q$1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$Q$" & j).AutoFilter Field:=8, Criteria1:="ABC"
ActiveSheet.UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
ActiveSheet.ShowAllData
End If
How it works?
- The data begins at "A1"
- The code will read total rows
- Then assign a temporary cell in last cell in first row to check whether is there any data or not to be filtered. Then clear the temporary cell value
- If got data to filter then filter then delete filtered rows. After filter, show all data
- If no data to filter then do nothing
Where:
- j = Total Rows
- "ABC" = Criteria to filter is "ABC". Change to your requirement
- C8:C8 = Criteria to be filtered in column number 8 or column H. Change to your requirement
- "$A$1:$Q$1" = header to filter. Change to your requirement
- AutoFilter Field:=8 is column number 8 or column H. Change to your requirement
No comments:
Post a Comment