VBA: Filter range by dropdown list selection

Martin_H

Board Regular
Joined
Aug 26, 2020
Messages
190
Office Version
  1. 365
Platform
  1. Windows
Morning all,

I want to filter the range "D4:D590" by value selected from dropdown list located @ the cell "DK1".

So basically when I select value "apples" from dropdown list @ cell "DK1" I want to see only rows with value "apples" in range "D4:D590".

Thank you.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
hi,

try
VBA Code:
sub frange()
myvalue = range("DK1").value
    With ActiveSheet
        Range("A:D").AutoFilter Field:=4, Criteria1:=myvalue
    End With
end sub
 
Upvote 0
Thank you for your reply.

I am getting 1004 error. Application-defined or object-defined error.
 
Upvote 0
try
VBA Code:
sub frange()
dim myvalue as string
myvalue = Activesheet.range("DK1").value
    With ActiveSheet
        Range("A:D").AutoFilter Field:=4, Criteria1:=myvalue
    End With
end sub
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "DK1" Then
      Range("D4:D590").AutoFilter 1, Target.Value
   End If
End Sub
This needs to go in the relevant sheet module & will change the filter whenever DK1 is changed.
 
Upvote 0
Both ideas working great. Thank you for your time guys. I appreciate it.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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