Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of Three filters and a Delete Rows VBA Code in Excel

Status
Not open for further replies.

gbloemke

Technical User
Mar 29, 2013
11
US
I have a spreadsheet with 7000 lines of data. I want to delete certain rows of data that meet criteria. I need to filter column V to see only a criteria of "NEP". I then want to filter column P to see only a criteria of "Groom". I then want to filter column G to see only a criteria of "ONSP*". Lasterly, I will then delete all rows that meet the criteria of "ONSP*" in that column G. My code runs the first "filter" just fine, but does not move past the 2nd "filter" command. I'm missing something key about having multiple filters using VBA code language. Can you help?

Here's my code:
======================================
Sub DeleteRows()

' Delete all ONSP's from column G

Range("V1").Select
With Range("V1", [V7000].End(xlUp))
.AutoFilter Field:=1, Criteria1:="NEP"
End With

Range("P1").Select
With Range("P1", [p7000].End(xlUp))
.AutoFilter Field:=1, Criteria1:="Groom"
End With

Range("G1").Select
With Range("G1", [g7000].End(xlUp))
.AutoFilter Field:=1, Criteria1:="ONSP*"
.Offset(1, 0).Resize(.Rows.Count - 1, 1).EntireRow.Delete
.AutoFilter
End With

End Sub
=============================
Thanks,
Greg
 
hi,

Presumably this is all ONE TABLE. Yes? If not, then you have other problems.

Assuming yes, turn on your macro recorder and record setting these three filters. Turn off your macr orecorder and observe your recorded code.

Post back if you have further questions.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Sometimes, the answer is simple and right under my nose. You were right Skip. I was thinking far too complicated about VBA code on this one. Back to basics for me.

Thank you,
Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top