Solved

Excel Filter macro on two variables

Posted on 2014-02-12
2
409 Views
Last Modified: 2014-02-12
Sub Macro3()
'
' Macro3 Macro
'

'
    ActiveSheet.Range("$A$39:$DL$22265").AutoFilter Field:=52, Criteria1:= _
        ">=Para_Age_Min", Operator:=xlAnd, Criteria2:="<=Para_Age_Max"
End Sub


I have two variable
Para_Age_Min and and Para_Age_Max and am trying to write a macro which will sort a database ("$A$39:$DL$22265") by filtering only records that are >=Para_Age_Min and <=Para_Age_Max

Para_Age_Min and Para_Age_Max are numbers such as 2 and 6 and so I am trying to filter for example >=2 and <=6 for records in column 52

I am sure this problem would probably have been addressed in the past but my macro wont work as it return no records when it filters.

ie no records meet the criteria even though there are records that

I havent attached a file as it is simply too big but would appreciate if anybody can see if my rather simple macro has some form of logic or other problem

Thanks

Paul Collins
0
Comment
Question by:snapper1
2 Comments
 
LVL 49

Accepted Solution

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

if they are variables

pls try

Sub Macro3()
'
' Macro3 Macro
'
    ActiveSheet.Range("$A$39:$DL$22265").AutoFilter Field:=52, Criteria1:= _
        ">=" & Para_Age_Min, Operator:=xlAnd, Criteria2:="<=" & Para_Age_Max
End Sub

Open in new window


if named ranges
[code]Sub Macro3()
'
' Macro3 Macro
'
    ActiveSheet.Range("$A$39:$DL$22265").AutoFilter Field:=52, Criteria1:= _
        ">=" & Range("Para_Age_Min"), Operator:=xlAnd, Criteria2:="<=" & Range("Para_Age_Max")
End Sub

Open in new window


Regards
0
 

Author Comment

by:snapper1
ID: 39855484
Thank you for your very quick response.
The second one worked first go . The first may also worked but as I was using a named range I only tried the second
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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

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