Data Filter Using Data Validation List

psulions83

Board Regular
Joined
Nov 16, 2015
Messages
127
Hello All,

I know I have done the below question before but for the life of me cannot remember and find the right answer.

I have a list in columns A-C. I have a dropdown in C1 with the unique value from column A. I was the list to filter based on what value I pick from the drop down. Can anyone help point me in the right direction?

Thanks!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hello All,

I know I have done the below question before but for the life of me cannot remember and find the right answer.

I have a list in columns A-C. I have a dropdown in C1 with the unique value from column A. I was the list to filter based on what value I pick from the drop down. Can anyone help point me in the right direction?

Thanks!

This is one way of doing it.

The code goes in the worksheet code module.

Try it with this sheet and then adapt it to meet your needs.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

  If Target.Count > 1 Then
    Exit Sub
  End If
  
  On Error Resume Next
  ActiveSheet.ShowAllData
  On Error GoTo 0
  
  If Target = Range("C1") Then

    ' Clear Filter.
    If Target.Value = "Clear" Then
      On Error Resume Next
      ActiveSheet.ShowAllData
      On Error GoTo 0
    Else
  
      ' Apply Filter.
      With ActiveSheet.Range("A3").Resize(Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row - 2, 3)
        .AutoFilter field:=1, Criteria1:=Range("C1").Value
      End With
  
    End If
  
  End If
 
End Sub

Recent Files.xlsm
ABC
1Clear
2
3Column 1Column 2Column 3
4853
5436
6246
7418
8366
9122
10828
11841
12614
13458
14736
15753
16784
17616
18131
19861
20756
21673
22514
23231
24851
25584
26733
27868
28427
29644
30615
31381
32851
33348
34366
35143
36588
37363
38547
39135
40116
41271
42872
43261
44556
45311
46222
47614
48377
49552
50457
51571
52384
53286
54211
55135
56434
57564
58846
59427
60221
61882
62464
63851
64768
65786
66852
67248
68618
69347
70721
71171
72173
73864
ToFilter
Cell Formulas
RangeFormula
A3:C3A3="Column " & COLUMN()
Cells with Data Validation
CellAllowCriteria
C1ListClear,1,2,3,4,5,6,7,8
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in C1. The macro assumes you have headers in row 1.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(0, 0) <> "C1" Then Exit Sub
    Range("A1").CurrentRegion.AutoFilter 1, Target.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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