Filtering Using A Dropdown List

tony68

New Member
Joined
Jun 2, 2020
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
Hi completely new to VBA but have managed to create a filter via a dropdown list using code

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" Then
If Range("B2") = "All" Then
Range("A5").AutoFilter
Else
Range("A5").AutoFilter Field:=2, Criteria1:=Range("B2")
End If
End If
End Sub

What I want to do now is add a second filter from a different dropdown list - is this possible?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Welcome to the Board tony68,

If you notice in your code you have Criteria1 then you should be able to add Criteria2.

Simply advice is record a macro to apply two filters and then stop the recording, check the code in the recording and it will give you the solution you want to apply.
 
Upvote 0
Thanks Trevor G I have tried recording a Macro but does not help me - possibly as I am not sure what exactly it is I am doing!!
 
Upvote 0
Ok then Tony please explain the second condition (criteria) and see if we can help.
 
Upvote 0
OK what I have is a large spreadsheet and I want to run a VBA code that filters out by Area Manager and the by Office Type. Where it shows Man A in row 1 cell 2 is a drop down list as is row 2 cell 2. So in essence I want to be able to select the appropriate manager from the drop down and then filter further by office type. There is a 3rd thing I want to do but lets try and crack this first. Hope makes sense.
Man A
Local Depot
RowLabelsOffice TypePostcodeArea Manager
2​
Newport West DODelivery OfficeNPMan A
4​
Chesterfield DODelivery OfficeSMan B
6​
Edinburgh LDLocal DepotEHMan C
21​
Gloucester North DODelivery OfficeGLMan A
23​
Gloucester South DODelivery OfficeGLMan B
36​
Kirkintilloch DODelivery OfficeGMan C
41​
London North West LDLocal DepotWMan A
57​
Bolton North DODelivery OfficeBLMan B
58​
Brinklow DODelivery OfficeMKMan C
59​
Bletchley DODelivery OfficeMKMan A
75​
Winton DODelivery OfficeBHMan B
77​
Nottingham LDLocal DepotNGMan C
80​
West Thurrock HUBHubRMMan A
 
Upvote 0
Have you thought of using Data Tables with Slicers that would provide you with enough options without code. In the example image there is a table (Your data example) I have highlighted it and then set it to be a Data Table (Insert Tab and Table on the left). Then In the Design tab that becomes available I have set to Slicers and you then just filter from them.
 

Attachments

  • Sample Table.jpg
    Sample Table.jpg
    98 KB · Views: 5
Upvote 0
No had not thought of that but something similar but was trying to avoid having a lot of "buttons" - full sheet has 20 area managers and 13 office types. Will give it a go though and see how it looks. Thanks for the tip.
 
Upvote 0
Hi Trevor yeah that looks good - probably looks more professional than a simple drop down list. One more question if I may - when I filter how do I get it to show only the topX sites?
 
Upvote 0
OK how would you get the top X sites now, is there a number system or something else, and what classes a site to be at the top?

It maybe a pivot table helps you
 
Upvote 0
There is an average per meter squared column so it would be the top X sites in that column - so if I filter on manager I will get say 300 building then if I filter on building type I will get say 105 buildings which is too many so what I ideally want to do is when selecting the filter by building type it only returns the top x. Hope that makes sense.
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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