Sub test()
Range("A2:A100").SpecialCells(xlCellTypeVisible).EntireRow.Delete
End Sub
Sub test()
lr = Cells(Rows.Count, 1).End(xlUp).Row
If lr > 1 Then
Range("A2:A" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If
End Sub
Option Explicit
Sub FilterData()
'Below is the complete program to delte only the visible filtered rows from a selected range.
If ActiveSheet.AutoFilterMode Then Selection.AutoFilter
ActiveCell.CurrentRegion.Select
With Selection
.AutoFilter
.AutoFilter Field:=2, Criteria1:="404665"
.Offset(1, 0).Select
End With
Dim numRows As Long, numColumns As Long
numRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
Selection.Resize(numRows - 1, numColumns).Select
With Selection
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
End Sub
Sub DeleteFilteredOutRows()
'
' DeleteFilteredOutRows Macro
'
Dim x As Integer, HelperC As Integer, LastRow As Integer
'Find LastRow
Range("A1").Select
LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
'Add Helper Column to identify if visible
Range("A1").Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
HelperC = ActiveCell.Column ' HelperC = Column number of helper column
ActiveCell.Value = "Visible?"
'If visible, add 1 to Visible column
For x = 2 To LastRow
If Rows(x).EntireRow.Hidden Then
Else
Cells(x, HelperC).Value = 1
End If
Next x
'If not visible(Visible column <> 1) then delete row
For x = 2 To LastRow
If Cells(x, HelperC).Value <> 1 Then
Rows(x).EntireRow.Delete
End If
Next x
Columns(HelperC).EntireColumn.Delete 'Delete Helper Column
Range("A1").Select ' Select cell A1
' Removes filters
On Error Resume Next
ActiveSheet.ShowAllData
End Sub
Sub DeleteFilteredOutRows()
'
' DeleteFilteredOutRows macro
'
Dim x As Integer, HelperC As Integer, LastRow As Integer
'Find LastRow
Range("A1").Select
LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
'Add Helper Column to identify if visible
Range("A1").Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
HelperC = ActiveCell.Column ' HelperC = Column number of helper column
ActiveCell.Value = "Visible?"
'If visible, add 1 to Visible column
For x = 2 To LastRow
If Rows(x).EntireRow.Hidden Then
Else
Cells(x, HelperC).Value = 1
End If
Next x
' Removes filters
On Error Resume Next
ActiveSheet.ShowAllData
'If not visible(Visible column <> 1) then delete row
For x = 0 To (LastRow - 2)
If Cells(LastRow - x, HelperC).Value <> 1 Then
Rows(LastRow - x).EntireRow.Delete
End If
Next x
Columns(HelperC).EntireColumn.Delete 'Delete Helper Column
Range("A1").Select ' Select cell A1
End Sub