Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Home
About
Books on Excel
Contact
Time and Date
Subscribe by RSS
Excel Semi-Pro
The other day I was reading a post over at the Contextures blog about Dynamic Dependent Excel Drop Downs and
realized that using an Excel Table would provide an alternative method that is both simple and flexible. Tables are available in Excel versions 2007, 2010, and 2011.
In this post Ill create a Table to hold the Categorys and Items, create three defined names using dynamic formulas, then use Data Validation to create two drop-down lists, the
second being dependent upon the first.
To create a defined name in Windows choose Formulas > Name Manager then click New. On a Mac choose Insert > Name > Define. This will bring up the New Name
dialog box that looks like the Edit Name screen-shot shown above.
excelsemipro.com/2011/05/a-dynamic-dependent-drop-down-list-in-excel/
1/10
9/7/13
Online Visitors: 6
We're offline!
Now cell A2 has a drop down button that shows the Header row of the Table. (Dont worry about extending this Data Validation down to more rows, well take care of that later.)
Column B will hold a drop-down list for the Item, which is dependent upon the Category. This takes two defined names to work properly.
This formula will return a reference to the Table column that matches the Category selection in cell A2 on Sheet1.
If I use Data Validation to create a drop-down list with the myItemList defined name Ill get eight items returned because Table1 has eight data rows. As you can see in the picture
below, the Vegetables item list has two blank lines, and the Other Stuff item list has one blank line. Not an elegant solution.
However, if you have a table that always has equal items (rows) in each column then this defined name formula will will work well for a Data Validation list.
excelsemipro.com/2011/05/a-dynamic-dependent-drop-down-list-in-excel/
2/10
9/7/13
The result is a dynamic drop-down list in the Item column thats dependent on the Category selection in column A, and returns the exact list.
Convert to a Table
Now its time to covert this to a Table, and by doing so the Data Validation will be preserved and automatically expand with the addition of more rows.
Select cell A2, then in Windows (Excel 2007, 2010) choose Insert > Table, verify the information in the Create Table dialog box, and click OK.
On a Mac (Excel 2011), select cell A2 then choose Tables > New > Insert Table with Headers.
At this point I normally turn off the Data Filter because its rather annoying.
As your Table expands, with more rows or columns, this dynamic drop-down list will work just fine. To create a new row in the Table with Data Validation press the Tab key
while the active cell is the last column of the last row.
excelsemipro.com/2011/05/a-dynamic-dependent-drop-down-list-in-excel/
3/10
9/7/13
In this case its best to use the first defined name (myItemList) in creating a dependent, drop-down list for Item. At least youll get all the data, even if it does have some blanks in the
list.
[UPDATE]
Ive had numerous questions about the details of this post so Im putting a link here to download the file.
Twitter 3
Share this:
Facebook 8
StumbleUpon
Related posts:
1.
2.
3.
4.
5.
excelsemipro.com/2011/05/a-dynamic-dependent-drop-down-list-in-excel/
4/10
9/7/13
5/10
9/7/13
Heres an example:
http://sdrv.ms/Zphkl8
6/10
9/7/13
=INDEX(Table1,1,MATCH(Table2[@Category],Table1[#Headers],0)):INDEX(Table1,COUNTA(INDEX(Table1,,MATCH(Table2[@Category],Table1[#Headers],0))),MATCH(T
(and as an added bonus, theres no need to select a particular cell when entering this formula)
You can then delete the MyItemList nameits no longer needed.
7/10
9/7/13
And if we wanted something in-between say the 3rd row or the 7th row, wed use theses:
=INDEX(SomeRange,3,1)
=INDEX(SomeRange,7,1)
But INDEX does something cool if you use two INDEX functions with a colon in between themit returns the entire RANGE that lies between the cell that the
first INDEX function points at, and the cell that the second INDEX function points atinclusive of the first and last references.
So for instance this would return an array of all the rows from row 3 to row 7 in the 20th column of SomeRange :
=INDEX(SomeRange,3,20) : INDEX(SomeRange,7,20)
If SomeRange started in A1, then this is the same as saying:
=T3:T20
Given this, we can return a dynamic range that dynamically references a discrete portion of a table using nothing but INDEX.
So for instance, say we have an Input table with a Master dropdown in a column called Master and a Slave dropdown in a column called Slave. And we
have a table called Database that lists the Master categories across the top in the headers, and the various slave categories beneath each Master heading.
We can build a dynamic range that references the Slave picklist depending on what the Master picklist is set to.
To reference the FIRST cell, we use this:
Formula 1: =INDEX(Database,1,MATCH(Input[@Master],Database[#Headers],0))
To reference the LAST cell, well start by first building a reference to the entire column:
Formula 2: =INDEX(Database,0,MATCH(Input[@Master],Database[#Headers],0))
And now well need to replace that zero with a count of the number of rows that contain text in the particular column we are referencing. To do that, we just wrap
Formula 2 in a COUNTA function:
Formula 3: =COUNTA(INDEX(Database,0,MATCH(Input[@Master],Database[#Headers],0)))
and then substitute Formula 3 into Formula 2 where the Zero is:
Formula 4:
=INDEX(Database, COUNTA(INDEX(Database,0,MATCH(Input[@Master],Database[#Headers],0))),MATCH(Input[@Master],Database[#Headers],0))
So Formula 1 references the first cell of interest, and Formula 4 references the LAST cell of interest. All we need to do now is put a colon between them, and call
it a day:
Final Formula: =INDEX(Database,1,MATCH(Input[@Master],Database[#Headers],0)): INDEX(Database,
COUNTA(INDEX(Database,0,MATCH(Input[@Master],Database[#Headers],0))),MATCH(Input[@Master],Database[#Headers],0))
excelsemipro.com/2011/05/a-dynamic-dependent-drop-down-list-in-excel/
8/10
9/7/13
Recent Posts
Where is Control+Home for Excel on a Mac
Extracting Integers and Fractions in Microsoft Excel
Excel without a Mac
Extract Time with the MOD Function in Excel
Extract Time from a Date-Time Number in Excel
Extract a Date from a Date-Time Number in Excel
Add Macro Button to the Toolbar in Excel 2011
Control + Home in Excel for Mac
Blog Comments and Inspiration
Break Even Calculation with an Unlocked iPhone and International Rates
Recent Comments
Gregory on Keyboard Shortcuts in Excel 2011
Vinay on Keyboard Shortcuts in Excel 2011
Ramoen on Date and Time Calculation in Excel
Ramoen on Date and Time Calculation in Excel
Gregory on Where is Control+Home for Excel on a Mac
Excel Links
A Dynamic Dependent Drop Down List
excelsemipro.com/2011/05/a-dynamic-dependent-drop-down-list-in-excel/
9/10
9/7/13
Chandoo.org
Contextures Blog
Excel Hero Blog
Peltier Tech Blog
The Imposing INDEX
The Spreadsheet Page Blog
Archives
Select Month
excelsemipro.com/2011/05/a-dynamic-dependent-drop-down-list-in-excel/
10/10