It is possible to make 2 dropdownlist with different based on 1 value in a cell?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 01:42:48

问题


After reading many tutorial, I managed to make a well effective dynamic dropdownlist

My question is , let's say I want to add a third depend cell, and the problem the name of MyCell is already used once

I'm using this line of code to bind the first dropdownlist (INDIRECT(SUBSTITUTE($U22," ","")&"Col")),1)

Is it possible to add to this line of code something like

(INDIRECT(SUBSTITUTE($U22+"Other"," ","")&"Col")),1)`

as to bind the second dropdownlist so I can name a cell :MyCellOther witch contains the other value I want to add


回答1:


I'll elaborate on what I meant in my comment above:

The name of a Named Range can be anything you want that isn't already used as a term by Excel. When naming your ranges, you should be careful to use logical terms which intuitively show what they mean. If you are using a series of similar names in an ordered list, consider simply numbering them 1 to 9, or instead consider using a 2D block of data as a single range. I will show you how to do both.

Explanatory Example of multi-tiered dropdown lists - 2 methods

Sheet1 is going to hold the end-user's dropdown selection. Sheet2 is going to hold your raw list database.

On Sheet1, assume A1 is a cell that allows a user to enter in what type of pie they want. There are 2 types: Fruit or Meat. Further, there are two sub-categories within each type: Fruit (Summer) / Fruit (Winter), or Meat (Red Meat) / Meat (Poultry).

If a user enters the type of pie they want in A1 (could be a dropdown itself), we want A2 to show a dropdown list that allows them to further choose which sub-category they want. Then, we want A3 to show a dropdown of each specific pie based on that sub-category within the main type.

Creating the Dropdown list in A1

On Sheet2, A1 enter "Fruit", and then on A2 enter "Meat". Select A1:A2 on sheet2, and name that range "MAIN_TYPES". On Sheet1, A1, make a dropdown list that is limited to "=MAIN_TYPES". This will create the first dropdown list.

Creating the sub-category dropdown list in A2 using a 2D block of data

First, organize your data on sheet2. On Sheet2 B1, type Summer, on C1 type Winter. On Sheet2 B2 type Red Meat, on C2 type Poultry. Select B1:C2, and name that range "SUB_CATEGORIES".

So, the user has already selected either Fruit or Meat. We want this dropdown list to only show the sub-category of that particular type. We can do this by referencing the fact that Sheet2 row 1 contains the fruit pies, and row 2 contains the meat pies.

On Sheet1 A2, make the cell a dropdown list which refers to the list SUB_CATEGORIES. But, we want to limit it so that it doesn't show the categories for the 'other' pie type. If we wanted to hardcode this to only show the Fruit sub-categories, we could use:

=INDEX(SUB_CATEGORIES,1,0) 

This says - take row 1 of SUB_CATEGORIES (the fruit row), and for the column, take ALL columns (we show this by putting the '0' above; it assumes we want all the available columns, which is quite handy).

To make this dynamic and based on the selection of A1, we can replace the '1' above with the MATCH formula, which looks at where a specific search string was found in a row/column of data. Like so:

=INDEX(SUB_CATEGORIES,MATCH(A1,MAIN_TYPES,0)

This searches for the type of pie picked in A1, out of the MAIN_TYPES range, and then returns that row number to the INDEX Function. So now, this INDEX function returns a single row (and both columns) of the sub-categories, based on the row which aligns with the MAIN_Type chosen.

Creating the dropdown list in A3, using numbered Named Ranges

On sheet2, add in the final block of data - the specific list of each type of pie. On D1 type Peach, on D2 type Cherry, on D3 type Rhubarb; Name this list Fruit1 [this will be the summer fruits]. On E1 type Apple, on E2 type Pumpkin; Name this list Fruit2 [this will be the winter fruits]. On F1 type Beef, on F2 type Lamb; Name this list Meat1 [this will be the Red meats]. On G1 type Chicken; Name this cell Meat2 [this will be the Poultry].

Now, on Sheet1, cell A3, the user will need to pick which pie out of the type and sub-category already chosen. If we wanted to hardcode this to be winter fruits, the formula for the dropdown list would simply be:

=Fruit2

But, we want to only show the winter fruit options if that was chosen above. Consider: if we wanted to allow the user to just type "Meat1" into A4, we could put the following formula in A3, and it would show that list:

=INDIRECT(A4)

Instead of having the user type in the name of the Sub Category, we will take the information they have already provided, and combine it to create that name. Specifically, we will combine (1) the main of pie the user has already chosen, with (2) the Column number of the Sub_Category they have chosen. The Main type they chose is simply the text in A1. The column number of the Sub Category is found using the Index & Match function, similar to above:

=MATCH(A2, INDEX(SUB_CATEGORIES,MATCH(A1,MAIN_TYPES,0),0)

Remember above, the formula '=INDEX(SUB_CATEGORIES,MATCH(A1,MAIN_TYPES,0)' gave us the row that aligned with either Fruit or Meat. Here we take that row, and use MATCH to find the column # that aligns with A2. We can combine all of this together with the text in A1, and it will give us the name of the Sub Category for the final dropdown list in A3:

=INDIRECT(A1 & MATCH(A2, INDEX(SUB_CATEGORIES,MATCH(A1,MAIN_TYPES,0),0))

And that's all there is to it.

The above can be extrapolated for your data, but it shows how to (1) do a dropdown list that refers to a named list of MAIN_TYPES; (2) Do a dropdown list that looks for a specific row in a 2D range of SUB_CATEGORIES; (3) create a 'cascading' dropdown list using the Indirect function; and (4) use numbers in the name of a range to refer to multiple similar lists.



来源:https://stackoverflow.com/questions/31948083/it-is-possible-to-make-2-dropdownlist-with-different-based-on-1-value-in-a-cell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!