VBA-Delete all Filtered Rows

poikl

Active Member
Joined
Jun 8, 2002
Messages
484
Platform
  1. Windows
Hi,
I hope you can please help me? I have a Macro which one command Filters all Rows in Excel Sheet which show P in ColD.
I need the VBA Code to Delete those exposed rows only which can vary day to day and then afterwards to Unfilter sheet.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
try this
Code:
Sub DELETE_VISIBLE_ ROWS_AFTER_FILTER()

    lr = Cells(Rows.Count, 1).End(xlUp).Row
    If lr > 1 Then
        Range("A2:r" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    End If
End Sub
 
Last edited:
Upvote 0
I wouldn't bother about using a filter which can be slow , do it directly like this:
Code:
Sub test()
lastrow = Cells(Rows.Count, "D").End(xlUp).Row
inarr = Range(Cells(1, 4), Cells(lastrow, 4))
For i = lastrow To 1 Step -1
 If inarr(i, 1) = "P" Then
  Range(Cells(i, 1), Cells(i, 1)).EntireRow.Delete
 End If
Next i


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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