Solved

Filter Range problem in Excel

Posted on 2013-10-23
1
232 Views
Last Modified: 2013-10-23
Hi Guys, I recorded a Macro for a daily process whereby I put an auto-filter on row 3.Then do End(xlDown) and copy the region. However, the Macro recorded the exact Row range and it will be variable every day so I need to adapt it.
Rows("3:3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$3:$R$166").AutoFilter Field:=13, Criteria1:=">=1", _
        Operator:=xlOr, Criteria2:="<=-1"

Any ideas?

Justin
0
Comment
Question by:Justincut
1 Comment
 
LVL 6

Accepted Solution

by:
Michael earned 500 total points
ID: 39593783
Hello Justin,

try the following:
Dim lr as long
lr = Cells(Rows.Count, "A").End(xlUp).Row

Rows("3:3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$3:$R$" & lr).AutoFilter Field:=13, Criteria1:=">=1", _
        Operator:=xlOr, Criteria2:="<=-1"

Open in new window

where Cells(Rows.Count, "A").End(xlUp).Row finds the last row used in column A.
If needed, replace A with a column in which there's always a value in the last row.

--
Btw, you can also leave this part out:
Rows("3:3").Select
    Selection.AutoFilter


So, this works as well:
Rows("3:3").AutoFilter
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now