Auto filter to work from cell reference

Corleone

Well-known Member
Joined
Feb 2, 2003
Messages
841
Office Version
  1. 365
is is possible to do the above
e.g to have the auto filter set up so that it selects the option based on
the value in cell "d9" ?

or is easier to do via a macro?

thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Ive stumpled upon a part soloution to this by using the following code

Sub FILTER_AREA()
Dim bf As String
bf = Range("AREA").Value
Selection.AutoFilter Field:=3, Criteria1:="=*" & bf & "*", Operator:=xlAnd
End Sub

this appears to work by populating the custom dropdown in the autofilter with the cell content in the "AREA" range (cell "d9" on another worksheet)

however the problem i have is if the cell that it refers to in the range name (which is a dropdown) is selected as "(all)" when the macro runs, the filter returns no rows instead of all of them. as "(all)" is not an option in the custom filter dropdown

is their a way of adding into the above code so that if the cell is on (all) the autofilter selects
"(all)" from the filter dropdown options?
thanks
 
Upvote 0
Try (untested)

Code:
Sub FILTER_AREA()
Dim bf As String
bf = Range("AREA").Value
Select Case bf
    Case "(all)"
        Selection.AutoFilter Field:=3
    Case Else
        Selection.AutoFilter Field:=3, Criteria1:="=*" & bf & "*", Operator:=xlAnd
End Select
End Sub
 
Upvote 0
Try (untested)

Code:
Sub FILTER_AREA()
Dim bf As String
bf = Range("AREA").Value
Select Case bf
    Case "(all)"
        Selection.AutoFilter Field:=3
    Case Else
        Selection.AutoFilter Field:=3, Criteria1:="=*" & bf & "*", Operator:=xlAnd
End Select
End Sub
thanks for the reply

this doesnt quite work because the first section of the code looks for "(all)" as a category under the custom dropdown (which doesnt exist) , what i need it to do instead is for it to
select the first (all) which appears in the filter dropdown
 
Upvote 0
thanks for the reply

this doesnt quite work because the first section of the code looks for "(all)" as a category under the custom dropdown (which doesnt exist) , what i need it to do instead is for it to
select the first (all) which appears in the filter dropdown

My mistake, your code above works perfectly

thats another beer I owe you
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top