Search Contextures Sites ![]()
Excel Data Validation -- Create Dependent Lists With INDEX
Thanks to Roger Govier, who created this tutorial and sample file.
As an alternative to using INDIRECT to create dependent Excel data validation lists, you can use the non-volatile INDEX function.In this example, just 4 dynamic range names are used. Of these, 3 are used to create the basic framework of the method.
The fourth permits any number of subsidiary lists to be created to act as Dependent dropdown lists from the entry in the previous column, without having to define individual names for each list.
Create the First Dynamic Range
Our first List is going to be called Master
- Choose Insert | Name | Define
- Type a name for the first range -- Master
- In the Refers To box, enter an Index formula that defines the range size, based on the count of items in column A of the Lists sheet:
=Lists!$A$2:INDEX(Lists!$A:$A,COUNTA(Lists!$A:$A))- This will give a dynamic List starting with cell A2 and extending for as many entries as we create in column A
Add More Headings and Entries to Lists
Enter all the Region names as headings in cells B1:E1 of the Lists Sheet.
Then, under each Region heading, enter one or more countries from that region. (See screen shot below, or see the sample file)
Create the ValData Dynamic Range
On the Lists sheet is the range of data that will be used in all validations for the Data Entry sheet. Instead of referring to the sheet name as range for this data, which will grow as more validations are added, you'll create a Dynamic range.
- Choose Insert | Name | Define
- Type a name for the range -- ValData
- In the Refers To box, enter an Index formula that defines the range size, choosing say 100 rows and a count of the columns on the sheet =Lists!$A$2:INDEX(Lists!$1:$100,100,COUNTA(Lists!$1:$1))
- This will give a dynamic List starting with cell A2 and extending for 100 rows and as many entries as we create in Row 1
- Click the Add button
The choice of 100 rows is arbitrary, and should just be sufficient to contain whatever is going to be the longest of your lists.
Next, because each individual List can have a different number of values, we need to create a Counter.
Create a Counter
The Counter is a variable which defines the length of each individual List. It is dynamic, and will alter dependent upon which column is being used, the column being returned by the Match function. A dynamic range will be created for the Counter.
Note: The range is relative, and refers to the cell to the left (A2) to determine its values, so it is vital that you have the cursor in cell B2 of the Data Entry sheet when defining the range.
- On the Data Entry sheet, type Europe in cell A2 (this is a temporary value, and you can delete it later)
- On the Data Entry sheet, select cell B2
- Choose Insert | Name | Define
- Type a name for the range -- Counter
- In the Refers To box, enter an Index formula that defines the range size, based on the count of numbers in the relevant column:
=COUNTA(INDEX(ValData,,MATCH('Data Entry'!A2,Lists!$1:$1,0)))- Click the Add button
Create the UseList Dynamic Range
This is the universal list name that will apply to all lists that are added to the sheet other than the Master list as previously described.
As new columns are added to the Lists sheet, their relevant used range is automatically dynamically created, and using UseList as the data source will apply to the whole of the validation areas on sheet Data Entry.
Note: Because the range is relative, and refers to the cell to the left (A2) to determine its values, it is vital that you have the cursor in cell B2 of the Data Entry sheet when defining the range.
- Place your cursor in cell B2 of Data Entry sheet.
- Choose Insert | Name | Define
- Type a name for the range -- UseList
- In the Refers To box, enter the following formula
=INDEX(ValData,1,MATCH('Data Entry'!A2,Lists!$1:$1,0)): INDEX(ValData,Counter,MATCH('Data Entry'!A2,Lists!$1:$1,0))- Click the Add button
Why the Cursor Placement is Important
- ValData has previously been defined as a range beginning in Row 2 of the Lists sheet.
- The UseList formula indexes the Valdata range, with 1 fixed value for the starting row element, in the first part of the formula and 1 dynamic value for the ending row element, in the second part of the formula.
- The formula has 1 relative value for the column element of the Index in both parts of the formula.
- Row in the first part is determined by the 1 in (Valdata,1, ...) and will therefore refer to Row 1 of ValData (therefore, row 2 of the Lists sheet).
- Row in the second part is determined by Counter in (Valdata,Counter, ...) , and Counter is a previously defined count, which will vary according to the number of entries in the validation list for the relative column.
- Column is determined by the Match of whatever is in the cell to the left of the cell using this dynamic range, MATCH('Data Entry'!A2,Lists!$1:$1,0) with the values of the List headings held in row 1 of the Lists sheet.
That is why it is so important to place the cursor in the correct starting cell when creating this named range.
The finished Data Entry sheet with sample Data
Expanding Columns on sheet Lists
You can add as many extra columns as you wish on sheet Lists. Each column has to have a heading which is a member of one of the other columns on the sheet, so that the new column added will be Dependent upon that heading.
For example, you could add a heading for US, and type a list states in that column. Next, you could add the state names as headings in row 1, and type a list of city names for each state.
You do not need to define any new names, as the Uselist dynamic range name will automatically deal with that for you.
Download a sample
Excel data validation file
Download a sample Excel data validation file Excel Tutorials - Data Validation
Contextures Inc., Copyright ©2011
All rights reserved.