VBA to filter a table based on selected cell

cee_real

New Member
Joined
Mar 31, 2016
Messages
8
Hello,

I need a VBA to filter a table based on a selection from a dropdown on cell G5. The table is on the same sheet and the filter is on the second column of the table. The table is titled "Table35"

For example, I want to select "Monday" from the drop down on cell G5. Then, the table35 below will filter for only rows that say "Monday"
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

JustynaMK

Well-known Member
Joined
Aug 28, 2016
Messages
629
Office Version
365, 2013
Platform
Windows
Try this code:

Code:
Sub foo()    With Sheet1
        .ListObjects("Table35").Range.AutoFilter Field:=2, Criteria1:=.Range("G5").Value
    End With
End Sub
Change "Sheet1" to appropriate sheet name. Hope it helps.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,263
In the sheet's module:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$G$5" Then
        Me.ListObjects("Table35").Range.AutoFilter Field:=2, Criteria1:=Target.Value
    End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,098,863
Messages
5,465,129
Members
406,414
Latest member
Discorz

This Week's Hot Topics

Top