Solved

Excel Filter macro on two variables

Posted on 2014-02-12
2
416 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 51

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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 …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

729 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