You are on page 1of 15

1/19/2016

ExcelDataValidationDependentLists

(http://www.contextures.com/index.html)

Create Dependent Drop Down Lists


LimitthechoicesinanExceldropdownlist,byusingnamedrangesandtheINDIRECTfunction,tocreate
dependentdatavalidationlists.Forexample,selectFruitincolumnA,andonlyFruititemsappearinthedrop
downlistincolumnB

Sections
Video:DependentDataValidation
CreateNamedLists
ApplytheExcelDataValidation
TesttheExcelDataValidation
AddingaThirdDependentList
UsingTwoWordItems
UsingItemswithIllegalCharacters
UsingDynamicLists
Video:BlockChangesinFirstDropDown
BlockChangesinFirstDropDown
ClearDependentCellAfterSelecting
DownloadtheSampleFile

Video: Dependent Data Validation


Inthisdependentdatavalidationexample,ifacountryisselectedfromthefirstdropdown,onlythatcountry's
citiesappearinthenextcolumn'sdropdownlist.

http://www.contextures.com/xlDataVal02.html

1/15

1/19/2016

ExcelDataValidationDependentLists

However,youcanusetheExcelIFfunctiontomaketheselectionmoreflexible.Ifnocountryisselected,theCity
columnwillshowalistofworldcitiesinthedependentdropdownlist.

Different Drop Down ...

Create Named Lists


StartbycreatingNamedLists,whichwillbethechoicesinthedependentdatavalidationdropdownlists.Inthis
example,thefirstlistwillbenamedProduce.
ItcontainstheProducecategoriesFruitandVegetable.

1. Create the first Named List


a. Inanemptyareaoftheworkbook,typetheentriesyouwanttoseeinthedropdownlists.Theseshould
beonewordentries,tomatchthedependentlistnamesthatwillbecreated.Ifyouneedtouse
multiplewordentries,see:
UsingTwoWordItems
b. Selectthecellsinthelist(butnottheheading).Inthisexample,cellsB3:B4areselected
c. ClickintheNamebox,totheleftoftheformulabar
d. Typeaonewordnameforthelist,e.g.Produce.
e. PresstheEnterkey.

2. Create the supporting Named Lists


a. TypetheentriesyouwanttoseeintheExceldatavalidationdropdownlistforoneoftheProduce
categories.
b. Selectthecellsinthelist.
c. ClickintheNamebox,totheleftoftheformulabar
d. Typeaonewordnameforthelist,e.g.Fruit.Thisnamemustbeexactlythesameasthematching
entryintheProducelist.
http://www.contextures.com/xlDataVal02.html

2/15

1/19/2016

ExcelDataValidationDependentLists

e. PresstheEnterkey.

f. CreateanotherlistwiththeitemsforthenextProduceTypeVegetableinthisexample

Apply the Excel Data Validation


Next,datavalidationwillbeappliedonthedataentrysheet
ThecellsintheProductTypecolumnwillallowaList.
ThecellsintheItemcolumnwillusetheINDIRECTfunctiontoselectalist.
1.ApplytheExcelDataValidation
a. SelectthecellsinwhichyouwanttoapplyExceldatavalidationusingtheProducelist
b. OntheRibbon,clicktheDatatab,thenclickDataValidation.

c. FromtheAllowdropdownlist,chooseList
d. IntheSourcebox,typeanequalsignandthelistname,forexample:=Produce
e. ClickOK.

http://www.contextures.com/xlDataVal02.html

3/15

1/19/2016

ExcelDataValidationDependentLists

2. Create the Dependent Data Validation


a. SelectthecellsinwhichyouwanttoapplydependentdatavalidationusingtheFruitorVegetableList,
dependentonwhichProduceTypehasbeenselected
b. OntheRibbon,clicktheDatatab,thenclickDataValidation..
c. FromtheAllowdropdownlist,chooseList
d. IntheSourcebox,typeanequalsignandINDIRECTfunction,referringtothefirstdatacellinthe
ProduceTypecolumn:
Inthisexample,cellC2isactive,sotheformulawillrefertotheProductTypecellinrow2:
=INDIRECT(B2)
e. ClickOK.

Note:IfcellA2isempty,you'llseethemessageshownbelow.ClickYestocontinue.

Test the Dependent Data Validation


1. ClickonacellintheProduceTypecolumn,andselecteitherFruitorVegetable,fromtheProducedrop
downlist.
http://www.contextures.com/xlDataVal02.html

4/15

1/19/2016

ExcelDataValidationDependentLists

2. PresstheTabkeyonyourkeyboard,tomovetotheItemcolumn,inthesamerow.
3. IntheItemcolumn,clickthedropdownarrow,andselectanitem.ThedropdownlistshowseitherFruitor
Vegetableitems,dependingwhichhasbeenselectedintheProduceTypecolumn

NOTE:IfaProduceTypehasnotbeenselected,theItemdropdowninthatrowwill
notwork.

Adding a Third Dependent List


Youcouldaddanothersetofdependentdatavalidationdropdownliststhatdependontheselectionsinthefirst
twodropdowns.Forexample,selectacountryandregion,thenselectacityinthatregion.

1. Createthetwonamedrangesanddropdownlistsasdescribedabove.
2. Createanothersetofnamedranges,namingthemfortheavailablecombinationsinthefirsttwoExceldata
validationdropdowns.Forexample,youmightcreaterangesnamedCanadaOntarioandUSANewYork.

3. Forthethirddropdown,choosetoAllow:List,anduseaformulathatcombinestheentriesinthefirsttwo
columns,andremovesthespacesfromthenames.Forexample,incellD2,thedatavalidationformula
wouldbe:

=INDIRECT(SUBSTITUTE(B2&C2,"",""))

Using Two-Word Items


YoumayneedtohavetwoworditemsinthefirstExceldatavalidationdropdownlist.Forexample,yourchoices
are'RedFruit','GreenFruit'and'YellowFruit'
1. Createthefirstnamedrangeanddropdownlistasdescribedabove.
2. Createthesupportingnamedlists,usingonewordnames,e.g.RedFruit,GreenFruit,YellowFruit
http://www.contextures.com/xlDataVal02.html

5/15

1/19/2016

ExcelDataValidationDependentLists

3. Fortheseconddropdown,choosetoAllow:List,anduseaformulathatremovesthespacesfromthenames.
Forexample:
=INDIRECT(SUBSTITUTE(A2,"",""))

Using Items with Illegal Characters


YoumayneeditemsinthefirstExceldatavalidationdropdownlistthatcontaincharactersnotallowedinrange
names,suchastheampersand(&).

Forexample,yourchoicesare'RedFruit','GreenFruit'and'Yellow&OrangeFruit'.Forthedependentlists,you
cancreaterangeswithonewordnames,suchasYOFruit.Then,createalookuptable,whichlistseachitemin
thefirstExceldatavalidationdropdownlist,andtherangewhereitsdependentitemswillbestored.
Tostart,createtheitemlistsandthefirstExceldatavalidationdropdown:
1. Createthefirstnamedrangeanddropdownlistasdescribedabove.Inthisexample,therangeisnamed
ProductList,withvaluesincellsA6:A8.ThedropdownlistincellA2usesProductListasitssource.
2. Createthedependentlists,andnamethem,usingonewordnames,with"List"attheend,e.g.
RedFruitList,GreenFruitList,YOFruitList.Inthisexample,RedFruitListisinA11:A12,
YOFruitListisinA15:A16andGreenFruitListisinA19:20.
3. SelectanitemfromthedropdownlistincellA2.
Next,you'llcreatethelookuptable,tomatcheachitemwithitsdependentitems'rangename.
1. InthecolumntotherightoftheFruitListrange,enterthecodenameforeachitem'sdependentlist.For
example,YOFruitisenteredasthecodenameforYellow&OrangeFruit.
2. Namethelookuptable.Inthisexample,therangeA6:B8isnamedProductLookup.
3. SelectcellB2,andfromtheDatamenu,chooseValidation.
4. ChoosetoAllow:List.
5. FortheSource,enteraformulathatusesaVLookupformulatofindthedependentlist'srangenamea
combinationofthecodenameand"List".
Forexample:=INDIRECT(VLOOKUP(A2,ProductLookup,2,0)&"List")
WithRedFruitselectedincellA2,theVLookupformulawillreturnRedFruitListastherangenameforthe
dependentlist.TheRedFruitListitemswillbedisplayedincellB2'sdropdown.

http://www.contextures.com/xlDataVal02.html

6/15

1/19/2016

ExcelDataValidationDependentLists

Tocreatea3rddependentdropdownlist,usethesametechniques,tocreatelookuptablesanditemslists.

Inthescreenshotbelow,therearelookuptablesnamedRedFruitLookup,YOFruitLookupand
GreenFruitLookup.Itemslists,withthecodenamesand"List",havebeenaddedtotheworksheet.

Inthedatavalidationwindow,usethisformulaforthe3rddropdown:
=INDIRECT(VLOOKUP(B2,INDIRECT(VLOOKUP(A2,ProductLookup,2,0)&"Lookup"),2,0)&"List")
TheformulafindsthelookuptablebasedontheproducttypeselectedincellA2,e.g.RedFruitLook,andgetsthe
codefortheselectedproductMac.Itadds"List"tothecode,andshowstheitemsintheMacListrange.

Using Dynamic Lists


http://www.contextures.com/xlDataVal02.html

7/15

1/19/2016

ExcelDataValidationDependentLists

BecausetheINDIRECTfunctiononlyworkswithreferences,notformulas,thepreviousmethodfordependent
datavalidationwon'tworkwithdynamiclists.Instead,youcanusethefollowingmethod:
1. Createthefirstnamedrangeanddropdownlistasdescribedabove.
2. Createthesupportingnamedlists,andnamethefirstcellineachrange,e.g.cellB1isnamedFruitandcell
C1isnamedVegetables.

3. Namethecolumninwhicheachlistislocated,e.g.columnBisnamedFruitColandcolumnCisnamed
VegetablesCol
4. Fortheseconddropdown,choosetoAllow:List,anduseaformulathatcalculatesthelookuprange.For
example,ifthefirstdropdownlistisincellE2:

=OFFSET(INDIRECT($E2),0,0,COUNTA(INDIRECT(E2&"Col")),1)
iftwoworditemswillbeused,youcanincludetheSUBSTITUTEfunctioninthe
formula:
=OFFSET(INDIRECT(SUBSTITUTE($F2,"
","")),0,0,COUNTA(INDIRECT(SUBSTITUTE($F2,"","")&"Col")),1)

Video: Block Changes in First Drop Down


Toblockchangestothefirstlist,youcanchangethedatavalidationformula,sothelistdoesnotappearunless
thesecondcellisempty.Thisvideoshowsyouhowthistechniqueworks,andwritteninstructionsarebelowthe
video.

Block Changes in Exc...

Block Changes in First Drop Down


http://www.contextures.com/xlDataVal02.html

8/15

1/19/2016

ExcelDataValidationDependentLists

Withdependentdropdownlists,problemscanoccur,ifsomeonegoesbacktothefirstlist,andchangesit.Then,
thefirstandsecondselectionsaremismatchedforexample,inthescreenshotbelow,Vegetableisthefirst
choice,andBananaisselectedinthesecondcolumn.
Toblockchangestothefirstlist,youcanchangethedatavalidationformula,sothelistdoesn'tworkunlessthe
secondcellisempty.

InsteadofjustreferringtotheProducerangefortheProduceTypedropdown,theformulawillcheckforanentry
intheItemcolumn.
IftheItemcellisblank,theProduceTypedropdownwillshowtheProducelist
Ifanitemhasbeenselected,thedropdownwilltrytoshowtherangecreatedbytheINDIRECTfunction
"FakeRange".Becausethereisnorangewiththatname,theresultisanerror,andthedropdownwillnot
work.
Tochangetheformula:
1.
2.
3.
4.

Selectthedatavalidationcellsinthefirstcolumn
OntheRibbon'sDatatab,clickDataValidation
ForAllow,selectList
IntheFormulabox,type:

=IF(C2="",Produce,INDIRECT("FakeRange"))
5. ClickOK
Now,thedropdowninthefirstcolumnwon'tworkiftheItemhasbeenselectedinthatrow.

Clear Dependent Cell After Selecting


Intheprevioussection,thedatavalidationformulawasdesignedtopreventselectionsfromthefirstdropdown,
ifthecelltotherightcontaineddata.
Anotheroptionistouseamacro,toclearthedependentcell,aftermakingaselectinginthefirstdropdown.That
willpreventmismatchedselections.
Inthisexample,columnBcontainsadropdownlistofRegions.AfteryouselectaRegion,thedropdownlistin
columnCshowsthecustomersintheselectedregion.

http://www.contextures.com/xlDataVal02.html

9/15

1/19/2016

ExcelDataValidationDependentLists

Gobackandselectadifferentregion,andtheexistingcustomernamewillbecleared.

Add Event Code to Clear the Customer Cell


WhenyouselectaRegion,eventcodeclearsthecelltotheright.Toaddthecode,rightclickthesheettab,and
clickViewCode.
Pastethefollowingcodeontothesheetmodule.Youmightneedtochangethecolumnnumber,tomatchthe
columnnumberonyourworksheet.
PrivateSubWorksheet_Change(ByValTargetAsRange)
OnErrorResumeNext
IfTarget.Column=2Then
IfTarget.Validation.Type=3Then
Application.EnableEvents=False
Target.Offset(0,1).ClearContents
EndIf
EndIf
exitHandler:
Application.EnableEvents=True
ExitSub
EndSub

Download the Sample File


Downloadasamplefilefordependentdatavalidation(DataValDepend.zip)
Downloadasamplefilefor(DataValDepend.zip)dependentdatavalidationwithDynamicLists
(DataValDynamic.zip)
DownloadasamplefileforClearDependentCellAfterSelecting
(/datavalidationsamples/datavaldependclear.zip)

Get All the Excel News

http://www.contextures.com/xlDataVal02.html

10/15

1/19/2016

ExcelDataValidationDependentLists

Get All the Excel News


ForregularExcelnews,tipsandvideos,pleasesignupfortheContexturesExcelnewsletter.Youremailaddress
willneverbesharedwithanyoneelse.

GetExcel
News

Name:

Email:

Werespectyouremailprivacy
(https://www.aweber.com/permission.htm)

More Tutorials
DataValidationBasics(xlDataVal01.html)
DependentDropdownsfromaSortedList(xlDataVal13.html)
DependentListsWithINDEX(xlDataVal15.html)
HidePreviouslyUsedItemsinaDropdownList(xlDataVal03.html)
UseaDataValidationListfromAnotherWorkbook(xlDataVal05.html)
DataValidationCriteriaExamples(xlDataVal06.html)
DataValidationTips(xlDataVal08.html)
DataValidationWithComboBox(xlDataVal10.html)

Search
SearchContexturesSites
Search
__

Search
CustomSearch

http://www.contextures.com/xlDataVal02.html

11/15

1/19/2016

ExcelDataValidationDependentLists

More Tutorials
DataValidationBasics(xlDataVal01.html)
DependentDropdownsfromaSortedList(xlDataVal13.html)
DependentListsWithINDEX(xlDataVal15.html)
HidePreviouslyUsedItemsinaDropdownList(xlDataVal03.html)
UseaDataValidationListfromAnotherWorkbook(xlDataVal05.html)
DataValidationCriteriaExamples(xlDataVal06.html)
DataValidationTips(xlDataVal08.html)
DataValidationWithComboBox(xlDataVal10.html)

(http://www.contextures.com/datavalidationmultiselectpremium.html)

Contextures
Excelnews
byemail

Email:

Name(optional):

Signup
http://www.contextures.com/xlDataVal02.html

12/15

1/19/2016

ExcelDataValidationDependentLists
Werespectyouremail
privacy
(http://www.aweber.com/permission.htm)

(http://www.contextures.com/exceltoolsaddin.html)

http://www.contextures.com/xlDataVal02.html

13/15

1/19/2016

ExcelDataValidationDependentLists

(http://www.contextures.com/datavalidationmultiselectpremium.html)

(http://www.mothresource.com/104516.html)

(http://www.contextures.com/datavalidationmultiselectpremium.html)

http://www.contextures.com/xlDataVal02.html

14/15

1/19/2016

ExcelDataValidationDependentLists

(http://www.exceluser.com/cmd.php?Clk=2511398)

GetExcel
News

Name:

Email:

CopyrightContexturesInc.2016
PrivacyPolicy(/privacy.html)

(https://mvp.microsoft.com/enus/mvp/Debra%20%20Dalgleish7612)DebraDalgleish
(https://mvp.microsoft.com/enus/mvp/Debra%20%20Dalgleish7612)

Lastupdated:December30,20152:21PM

http://www.contextures.com/xlDataVal02.html

15/15

You might also like