Fri 19 Jun 2015

Article 16 – Dependent Data List 02 – Creating Flexible / Dynamic Dependent Data List even First Drop Down is Flexible

By |Friday, June 19th, 2015|Categories: Articles|Tags: , , , , , |0 Comments

--- The Excel file related to this article can be downloaded from Dependent Drop Down List 02 ---

In Article 15, we saw that our Dependent Data list can grow / reduce vertically but we had fixed the horizontal range. Now, we will remove this restriction and our data list can grow / reduce vertically as well as horizontally.

1. Prepare the formula for first drop down.

In article 15, we saw that it is very simple i.e. $F$1:$K$1. Let's assume that maximum it can grow till Z1. In this case, we need to prepare a formula which will give us a range of $F$1:$K$1 within the range of $F$1:$Z$1 if South America is selected. If another entry is added or deleted, it should adjust appropriately.

The formula in this case would be -

=OFFSET($F$1,0,0,1,COUNTA($F$1:$Z$1))

(Though OFFSET is a volatile formula but simplicity of OFFSET is a reason to use)

2. Prepare the formula for second drop down

The formula was already there, only change is that $K is replaced by $Z. (As I said earlier 12 is a number till which the list can grow. You can put any number say 100, 900 etc.)

=OFFSET(INDEX($F$1:$Z$12,,MATCH($A$2,$F$1:$Z$1,0)),1,0,
COUNTA(INDEX($F$2:$Z$12,,MATCH($A$2,$F$1:$Z$1,0))))

3. Create the first drop down list and second drop down list utilizing above formulas.

Select A2 > Data tab > Data Validation > Data Validation > Choose List in Allow: and in source put

=OFFSET($F$1,0,0,1,COUNTA($F$1:$Z$1))

Select B2 > Data tab > Data Validation > Data Validation > Choose List in Allow: and in source put

=OFFSET(INDEX($F$1:$Z$12,,MATCH($A$2,$F$1:$Z$1,0)),1,0,
COUNTA(INDEX($F$2:$Z$12,,MATCH($A$2,$F$1:$Z$1,0))))

Now, your dynamic drop down list which can grow vertically as well as horizontally is ready.

Sat 06 Jun 2015

Article 15 - Dependent Data List 01 - Creating Flexible / Dynamic Dependent Data List

By |Saturday, June 06th, 2015|Categories: Articles|Tags: , , , , , , , |0 Comments

---- Excel file related to this article can be downloaded from Dependent Drop Down List ----

In this article, I want to create a dynamic dependent data list. It means that entries can be added, removed at any point of time without impacting your Dependent Data List. Without making matter complicated, this article assumes that first level is fixed and second level can keep changing. In second article of this series, I am going to remove this dependency also, hence both first and second level of entries can be removed / added in second article. The examples which I am going to show is one level of dependency but same logic can be extended to any level of dependencies.

1. Create the right layout for your dependent data list

Suppose, you have a list of 6 continents and you want to display the countries on the basis of continents selected. The step 1 is to layout your data properly.

Below, is the layout which you need to use. First row will contain the name of continents (i.e. first level drop down values) and below them will be the list of countries (i.e. second level of drop down values)

No blanks are allowed in between the list entries. Blanks can be only at the end.

Dependent Drop Down Layout

2. Create the first drop down

Let's assume that cell A1 needs to contain the first drop down.

Select A2 > Data tab > Data Validation > Data Validation > Choose List in Allow: and in source put $F$1:$K$1

First Dropdown

3. Prepare the formula for second drop down

Now, it can be simplified to finding the range which contains first drop down value in  first row. For example, if I select South America, I should be able to get the range $K$2:$K$12 (I have taken $K$12 for illustration purpose only. You can have any range. The trick will be to show only the values from $K$2:$K$6 in case of South America, $H$2:$H$5 in case of Australia and so on)

The range can be located by INDEX - MATCH combination as shown below. Notice, there are two commas after $K$12 which indicates that all rows should be selected for the column in the range $F$2:$K$12

=INDEX($F$2:$K$12,,MATCH($A$2,$F$1:$K$1,0))

This formula gives a range of $K$2:$K$12 for South America.

4. Create the second drop down

Let's assume that we want to create the second drop down in B1.

Select B1 > Data tab > Data Validation > Data Validation > Choose List in Allow: and in source put

=INDEX($F$2:$K$12,,MATCH($A$2,$F$1:$K$1,0))

Now, select a continent name in A1 and you will have list of countries shown in dependent drop down.

Second Dropdown with Blanks

5. Remove the blanks from second dropdown

We notice that there are blanks in second drop down at the end of the list. We need to remove these.

The logic, we will adopt is this - We have got the range in step 3. Now we need to count the non blank cells in that range and use OFFSET to get the required range.

=OFFSET(INDEX($F$1:$K$12,,MATCH($A$2,$F$1:$K$1,0)),1,0,
COUNTA(INDEX($F$2:$K$12,,MATCH($A$2,$F$1:$K$1,0))))

Note - INDEX($F$1:$K$12,,MATCH($A$2,$F$1:$K$1,0)) is first part of OFFSET and part within COUNTA making matter very simple. Hence, the formula is OFFSET("index formula",1,0,COUNTA("index formula")). In first INDEX, in place of $F$1:$K$12 we can put $F$1:$K$1 also. But as I said, I want to keep uniformity and make matter simple by having a very simple formula OFFSET("index formula",1,0,counta("index formula")).

INDEX($F$1:$K$12,,MATCH($A$2,$F$1:$K$1,0)) - Gives $K$1 in case of South America, $G$1 in case of Asia and so on. But, our range needs to start from second row i.e. $K$2 in case of South America, $G$2 in case of Asia and so on. Notice 1 in bold within OFFSET, it shifts the reference by 1 row. Hence, it makes $K$1 to $K$2 and so on.

COUNTA(INDEX($F$2:$K$12,,MATCH($A$2,$F$1:$K$1,0))) - Gives number of non blank cells. In case of Asia, it is 6. Hence, our reference becomes $G$2:$G$6.

6. Put the above formula in Dependent Data List.

Select B2 > Data tab > Data Validation > Data Validation > Choose List in Allow: and in source put

=OFFSET(INDEX($F$1:$K$12,,MATCH($A$2,$F$1:$K$1,0)),1,
0,COUNTA(INDEX($F$2:$K$12,,MATCH($A$2,$F$1:$K$1,0))))

Now, you have perfect looking dependent data list.

Second Dropdown without Blanks