Solved

Excel Filter macro on two variables

Posted on 2014-02-12
2
412 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 50

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
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.
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 …
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…

749 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