• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Autofilter a fixed range based on value picked from a drop down list

Hi, I am working on a vba that auto filter a range (A10:I5000) based on a cell value in A2 (which is a dropdown list) on the same sheet

The code is deprived from a macro that I recorded, however, nothing happens when I run it.

Attached is the file that I am working on, thank you.


Code:
Public Sub Sort_test()

If Sheets(1).Range("A2").Value = "*EBR" Then
Sheets(1).Range("$A$10:$I$5000").AutoFilter Field:=2, Criteria1:="=*R*", _
        Operator:=xlAnd, Criteria2:="=*EB*"

If Sheets(1).Range("A2").Value = "*CBR" Then
Sheets(1).Range("$A$10:$I$5000").AutoFilter Field:=2, Criteria1:="=*R*", _
        Operator:=xlAnd, Criteria2:="=*CB*"
       
End If
End If

End Sub
 

Attachments

  • 047Test.xls
    496 KB · Views: 1
It would and could do more
if Sheets(1).Range("A2").Value would be "*EBR" or "*CBR".
Did You get an idea?
 
It would and could do more
if Sheets(1).Range("A2").Value would be "*EBR" or "*CBR".
Did You get an idea?

I got the code responding by changing
Code:
 If Sheets(1).Range("A2").Value = "*EBR"Then
to
Code:
 If Sheets(1).Range("A2").Value = Sheets(3).Range("A1") Then
The data on Sheet 3 is the name list in for the drop down box on A2 in Sheet1.

Thanks for the insight.
 
Back
Top