Filter based on a cell's value.

Doug24

New Member
Joined
Jul 13, 2015
Messages
13
Is it possible to create a macro to filter data based on a cell value?

I have 34 worksheets and I need to filter them each day based on a name in cell K16. The data is
below from A17 to AM47 and needs to be filtered in column K (field 11). Also if the name doesn't
appear in column K is it possible to just default to the "Select All" filter option? The names aren't
constant and change daily. I'm doing the filtering manually now and would like to automate
it if possible.

Thanks in advance for any help,
Doug
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi. Try:
VBA Code:
Sub FilterTest()
 On Error Resume Next
 ActiveSheet.ShowAllData
 If [K16] <> "" And Application.CountIf([K17:K47], [K16]) > 0 Then [A17:AM47].AutoFilter 11, [K16]
End Sub
 
Upvote 0
Solution
VBA Code:
    Dim FoundRow As Variant
    ActiveSheet.AutoFilterMode = False
    FoundRow = Application.Match(Range("K16"), Range("K18:K47"), 0)
    If IsError(FoundRow) Then
        ActiveSheet.Range("$A$17:$AM$47").AutoFilter
    Else
        ActiveSheet.Range("$A$17:$AM$47").AutoFilter Field:=11, Criteria1:=Range("K16")
    End If
 
Upvote 0
Thank you mart37 - that does exactly what I need.
Now I have a couple of options to work with!

Thank you for your help.
Doug
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,736
Members
448,988
Latest member
BB_Unlv

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