Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel Filter macro on two variables

Posted on 2014-02-12
2
Medium Priority
?
422 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
[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
2 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

618 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