0

I have following code in which I have tried to applied 3 filters, now what I want is, to apply this filter criteria based on named range I have stored relevant value in specific cell and given names to that range

for first criteria i.e. >=200 named range is VOLUME

for second criteria i.e. >=0.07 named range is MOVE

for third criteria i.e. >=400 named range is STRENTH

So what are the changes that I need to make in following code?

Sub FILTER2()

'FILTER CRITERIA
ActiveSheet.Range("$A$2:$AC$500").AutoFilter Field:=6, Criteria1:=">=200", _
    Operator:=xlAnd
ActiveSheet.Range("$A$2:$AC$500").AutoFilter Field:=21, Criteria1:=">=0.07" _
    , Operator:=xlAnd
ActiveSheet.Range("$A$2:$AC$500").AutoFilter Field:=28, Criteria1:=">=400" _
    , Operator:=xlAnd

Range("A1").Select
End Sub
5
  • 1
    See this link Commented Nov 27, 2019 at 8:05
  • 1
    Can you clarify which value is in your named range? Is it 200 or >=200? If the first, your criteria should be ">=" & Range("Volume").value. If the second it should just be Range("Volume").value Commented Nov 27, 2019 at 8:06
  • value is in my named range is 200 Commented Nov 27, 2019 at 8:07
  • You might want to refrain from using ActiveSheet. Since you will also want to refer to a specific sheet holding your named ranges, a With statement seems at place here. Commented Nov 27, 2019 at 8:09
  • I got your point, thank you to all of you for help me. Commented Nov 27, 2019 at 8:13

2 Answers 2

1

As per my comment, you might want to consider a With statement, better not to refer to ActiveSheet

Sub FILTER2()

With Sheet1 'Change according to your sheets CodeName
    .Range("$A$2:$AC$500").AutoFilter 6, ">=" & .Range("VOLUME")
    .Range("$A$2:$AC$500").AutoFilter 21, ">=" & .Range("MOVE")
    .Range("$A$2:$AC$500").AutoFilter 28, ">=" & .Range("STRENTH")
End With

End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

yes, it helped me a lot, thq for giving your valuable time to share ans.
0

you can try defining a variable to contain the value of your named range. Named Range in your sheet as "Volume" then i can store that value in var namedRange1.

example below:

Sub FILTER2()  

namedRange1 = range("Volume")

'FILTER CRITERIA
ActiveSheet.range("$A$2:$AC$500").AutoFilter Field:=6, Criteria1:=">=" & namedRange1, _
    Operator:=xlAnd

....same with the other lines, just define new variable to contain new named range

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.