Setting up dependent dropdown lists in Excel using formulas

Deutz

Board Regular
Joined
Nov 30, 2009
Messages
191
Office Version
  1. 365
Platform
  1. Windows
Hi and thanks in advance,

I am trying to set up 2 Excel dropdown lists, one dependent on the other, using formulas if possible. I have looked over a lot of suggestions on the web but not found exactly the scenario I need.

Here is an example of the data the lists will be based on:

Country
Year:
2018
2019
2020
Australia123
Czech Republic88.1214
Venezuala7
Switzerland2.244
Norway3.4555
USA100
...

So the 1st dropdown list contains the years: 2018, 2019, 2020

When a year is selected in the 1st dropdown list, it should load the 2nd dropdown list with all the countries that have a value in the selected year column.

For instance, if 2018 was selected in the 1st dropdown list then load the following countries in the 2nd dropdown list: Australia, Switzerland, Norway

When the user makes a selection in the 1st dropdown list I would also like to clear any visible value in the 2nd dropdown llst.

Thanks again
Deutz
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
The possible solutions depend on your excel version. I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Thanks for the reminder to update my Account details. I am using Office 365 on Windows.
 
Upvote 0
Thanks for the profile update. Excel 365 (provided you have the FILTER function) makes the second drop-down very easy.

Use a spare column (I have used col G) which can be hidden once the formula is added.
The G2 formula needs to be entered in that cell only and the other results will automatically 'spill' down to other rows as required.
The Data validation formulas are shown below my sheet.

To clear the second cell when the first is altered requires vba. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1.
3. Close the Visual Basic window & test.
4. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm).

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("J1")) Is Nothing Then Range("J2").ClearContents
End Sub

Deutz 1.xlsm
ABCDEFGHIJ
1CountryYear:201820192020Year2018
2Australia123AustraliaCountry
3Czech Republic88.1214Switzerland
4Venezuala7Norway
5Switzerland2.244
6Norway3.4555
7USA100
8
Sheet1
Cell Formulas
RangeFormula
G2:G4G2=IF(J1="","Select Year First",FILTER(A2:A7,INDEX(C2:E7,0,MATCH(J1,C1:E1,0))<>""))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
J1List=$C$1:$E$1
J2List=G2#



1598505521853.png
 
Upvote 0
Thanks for the profile update. Excel 365 (provided you have the FILTER function) makes the second drop-down very easy.

Use a spare column (I have used col G) which can be hidden once the formula is added.
The G2 formula needs to be entered in that cell only and the other results will automatically 'spill' down to other rows as required.
The Data validation formulas are shown below my sheet.

To clear the second cell when the first is altered requires vba. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1.
3. Close the Visual Basic window & test.
4. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm).

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("J1")) Is Nothing Then Range("J2").ClearContents
End Sub

Deutz 1.xlsm
ABCDEFGHIJ
1CountryYear:201820192020Year2018
2Australia123AustraliaCountry
3Czech Republic88.1214Switzerland
4Venezuala7Norway
5Switzerland2.244
6Norway3.4555
7USA100
8
Sheet1
Cell Formulas
RangeFormula
G2:G4G2=IF(J1="","Select Year First",FILTER(A2:A7,INDEX(C2:E7,0,MATCH(J1,C1:E1,0))<>""))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
J1List=$C$1:$E$1
J2List=G2#



View attachment 21167
Thanks so much for your solution Peter, however I don't have access to the FILTER function as is says it is invalid when I try to use it. I do have Office 365 installed though.
 
Upvote 0
I don't have access to the FILTER function as is says it is invalid when I try to use it. I do have Office 365 installed though.
Not all 365 subscribers have all the functions yet. It shouldn't be too long though (I hope ?)

Until then, you can try this, with a similar setup but not such simple formulas/validation. You still need the vba to do the clear.
G2 formula is copied down as many rows as the country list in column A.


Deutz 1.xlsm
ABCDEFGHIJ
1CountryYear:2018201920204Year2019
2Australia123AustraliaCountry
3Czech Republic88.1214Czech Republic
4Venezuala7Venezuala
5Switzerland2.244USA
6Norway3.4555 
7USA100 
Sheet3
Cell Formulas
RangeFormula
G1G1=COUNTIF(G2:G7,"?*")
G2:G7G2=IF(AND(J$1="",ROWS(G$2:G2)=1),"Select Year First",IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW(A$2:A$7)/(INDEX(C$2:E$7,0,MATCH(J$1,C$1:E$1,0))<>""),ROWS(G$2:G2))),""))
Cells with Data Validation
CellAllowCriteria
J1List=$C$1:$E$1
J2List=OFFSET(G2,,,G1)
 
Upvote 0
Not all 365 subscribers have all the functions yet. It shouldn't be too long though (I hope ?)

Until then, you can try this, with a similar setup but not such simple formulas/validation. You still need the vba to do the clear.
G2 formula is copied down as many rows as the country list in column A.


Deutz 1.xlsm
ABCDEFGHIJ
1CountryYear:2018201920204Year2019
2Australia123AustraliaCountry
3Czech Republic88.1214Czech Republic
4Venezuala7Venezuala
5Switzerland2.244USA
6Norway3.4555 
7USA100 
Sheet3
Cell Formulas
RangeFormula
G1G1=COUNTIF(G2:G7,"?*")
G2:G7G2=IF(AND(J$1="",ROWS(G$2:G2)=1),"Select Year First",IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW(A$2:A$7)/(INDEX(C$2:E$7,0,MATCH(J$1,C$1:E$1,0))<>""),ROWS(G$2:G2))),""))
Cells with Data Validation
CellAllowCriteria
J1List=$C$1:$E$1
J2List=OFFSET(G2,,,G1)
Thanks so much Peter. I will test this out tomorrow. Cheers
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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