Search code examples
excelvalidationexcel-formuladynamicexcel-2021

How to make Dynamic Drop Down Menu


I have two Drop Down Menus and I want to make the second show values based on what I picked in the first one.
I used IF function in data validation but it doesn't work.

Here is the example:Example
I have two named ranges country and city.
I have used this formula in city drop down to show the first us cities if I selected us, if not show all, but it doesn't work :
=IF($E$3=$A$2,INDEX(city,2,1),city))

Data validation formula: =IF($E$3=$A$2,INDEX(city,2,1),city))


Solution

  • The simplest way to do it (but not the best since everything is hard-coded and has certain limitations) is to use named ranges with INDIRECT.

    Range A2:A3 is named "Country" and ranges B2:C2 and B3:D3 are named respectively "USA" and "Other".

    Cell G3 uses data validation, with the source being the name range "Country", and cells H3 uses data validation with the source being

    =INDIRECT($G$2)
    

    This way the available list of values for H2 changes depending on the content of G2.

    enter image description here