Solved

Delete rows from Autofilter

Posted on 2013-12-22
5
266 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 52

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 52

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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

623 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