Delete Non-Filtered Data

thardin

Board Regular
Joined
Sep 29, 2021
Messages
137
Office Version
  1. 365
Platform
  1. Windows
Here is the code I have to filter my data.
However, I want to delete not Hide all the rows (besides headings) that DOES not meet these 2 criteria.
How would I modify this AND the range that changes on a daily basis.


Sub FilterTest3()
' FilterTest3 Macro
' Keyboard Shortcut: Ctrl+p


Range("O2").Select

Selection.AutoFilter

ActiveSheet.Range("$A$1:$S$15").AutoFilter Field:=15, Criteria1:="=MFS*", _

Operator:=xlOr, Criteria2:="=#N/A"

End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
How about
VBA Code:
Sub FilterTest3()
' FilterTest3 Macro
' Keyboard Shortcut: Ctrl+p


Range("O2").Select

Selection.AutoFilter

With ActiveSheet
   .Range("$A$1:$S$1").AutoFilter 15, "<>MFS*", xlAnd, "<>#N/A"
   .AutoFilter.Range.Offset(1).EntireRow.Delete
   .ShowAllData
End With

End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub FilterTest3()
' FilterTest3 Macro
' Keyboard Shortcut: Ctrl+p


Range("O2").Select

Selection.AutoFilter

With ActiveSheet
   .Range("$A$1:$S$1").AutoFilter 15, "<>MFS*", xlAnd, "<>#N/A"
   .AutoFilter.Range.Offset(1).EntireRow.Delete
   .ShowAllData
End With

End Sub
.ShowAllData is showing a yellow error in Visual Basic when I run the Macro.
 
Upvote 0
Is it deleting the correct rows?
 
Upvote 0
In that case change that line to
VBA Code:
.AutoFilterMode = False
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

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