Solved

Filter Range problem in Excel

Posted on 2013-10-23
1
242 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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…

815 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

7 Experts available now in Live!

Get 1:1 Help Now