Solved

Delete rows from Autofilter

Posted on 2013-12-22
5
254 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
  • 3
  • 2
5 Comments
 
LVL 50

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 50

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Outlook Free & Paid Tools
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

808 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