Solved

Delete rows from Autofilter

Posted on 2013-12-22
5
261 Views
Last Modified: 2013-12-24
Here is some code that the VBA recorder captured.  How would I use this on other different filters thoughout project?  I want to apply a filter and delete to results getting rid of the absolute values that the recorder places in them.  Ideally I would like to place some code right after the autofilter.  Can this be done?  Please advise and thanks. -R-

    Rows("1:1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$O$1195").AutoFilter Field:=1, Criteria1:="=-", _
        Operator:=xlOr, Criteria2:= _
        "=-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
    Rows("6:6").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp

Open in new window

0
Comment
Question by:RWayneH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39734998
Hi,

pls try

Sub Macro()
    Rows("1:1").AutoFilter
    ActiveSheet.UsedRange.AutoFilter Field:=1, Criteria1:="=-", _
        Operator:=xlOr, Criteria2:= _
        "=-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
    LastRow = Cells(Cells.Rows.Count, 1).End(xlUp).Row
    LastColumn = Cells(1, Cells.Columns.Count).End(xlToLeft).Column
    Range(Range("A2"), Cells(LastRow, LastColumn)).SpecialCells(xlCellTypeVisible).Delete Shift:=xlUp
End Sub

Open in new window

Regards
0
 

Author Comment

by:RWayneH
ID: 39735040
Hey thanks!!
Forgive me but I would like to use this in other places and I need to understand how to enter into this... like select the column first?  Can you help me read this?

In Ln 2 you are telling it too turn on AutoFilter
In Ln 3,4,5,6 sets the filter... but how does it how that it is set in column A?  Is that declared by the field #
In Ln 7   ???  Defines LastRow, however what is the 1).End(xlUp.Row mean?
In Ln 8   ???  Defines LastColumn,  what does .End(xlToLeft).Column mean?  Is no left of ColA
In Ln 9, 10   ???  Starting in A2, delete the rows that are visible between LastRow, LastColumn?  -R-
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 39735659
Hi

you are right

Line 3:
Field:=1 defines the column (in that case A)

if your filter were from B1 to D1, field:=1 would be column B

Line 7:in XL 2010 Cells(Cells.Rows.Count, 1) defines the cell A1048576
I use Cells.Rows.Count because the number of rows is different between XL 2003 and XL 2007 and further

.End(xlUp) is like doing Ctrl-Arrow Up so i find the last non Empty Cell in the Column

.Row gives me the row number

Regards
0
 

Author Comment

by:RWayneH
ID: 39736671
Because this does not use an autofilter (which is fine) is leaves me with another issue.  I was going to change the autofilter to:

    ActiveSheet.UsedRange.AutoFilter Field:=3, Criteria1:= _
        "CUSTOM/SPECIAL"
    ActiveSheet.UsedRange.AutoFilter Field:=2, Criteria1:="=*SVC*", _
        Operator:=xlOr, Criteria2:="=*SRV*"

Then replace whatever was in column C (if anything) when "SERVICE PART"..
These will not be blank or have a space... but there was a couple other places that I was going to use this..  Any idea's.  Perhaps I need to do all the replacements without autofilters too?
0
 

Author Closing Comment

by:RWayneH
ID: 39738532
Worked great, will repost on trying to change a different column value based on a filter instead of deleting the results of the filter.  Thanks. -R-
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question