简体   繁体   English

如何基于另一个下拉列表中的选择创建动态(更改)下拉列表

[英]How to create a dynamic (changing) drop down list based on a selection from another drop down list

I've used this question to build my drop down list, but I want to know if this can be used to change one list based off of the selection on another. 我已经使用此问题来构建我的下拉列表,但是我想知道是否可以根据另一个选择来更改一个列表。

Here's the question: Data validation - Drop down list with no duplicates in excel 问题在这里: 数据验证-下拉列表,Excel中没有重复项

In my spreadsheet, I have columns like so: 在我的电子表格中,我有像这样的列:

Clients    Stores

Client1    Store1
Client2    Store2
Client3    Store3
...        ...

Say in the Clients list, you select client1. 在“客户端”列表中说,选择“ client1”。 I want to show only the stores that buy from client1 (say Store2 and Store6). 我只想显示从client1购买的商店(例如Store2和Store6)。 This list will be updated constantly, and new clients and stores will be added to the lists. 该列表将不断更新,并将新的客户和商店添加到列表中。 How would I go about doing this? 我将如何去做呢?

Thank you 谢谢

Edit: 编辑:

Here's the basic formula that I used to create my lists: 这是我用来创建列表的基本公式:

=IFERROR(INDEX(A$2:INDEX(A:A, MATCH("zzz",A:A )), MATCH(0, COUNTIF(Z$1:Z1, A$2:INDEX(A:A, MATCH("zzz",A:A ))&""), 0)), "")

Edit #2: 编辑#2:

Here's a better representation of my data: 这是我的数据的更好表示:

Order ID  Order Date   Client      Store
1234      MM/DD/YYYY   Client1     Store6
5678        ....       Client4     Store3
9101                   Client3     Store6
5432                   Client2     Store1

Based on this sample data: 基于此样本数据:

 A       B        C      D
order   date    client  store
1234            Client1 Store1
6543            Client2 Store1
5432            Client3 Store2
3214            Client1 Store3
9876            Client2 Store2
8765            Client4 Store5
7654            Client3 Store3

I created a Client List in Column F with formula: =IFERROR(INDEX($C$2:$C$8, MATCH(0,COUNTIF($F$1:F1, $C$2:$C$8), 0)),"") (paste into F2 and CTRL+Shift+Enter , Then drag formula down until Client names stop showing up). 我在F列中用以下公式创建了一个客户列表: =IFERROR(INDEX($C$2:$C$8, MATCH(0,COUNTIF($F$1:F1, $C$2:$C$8), 0)),"") (粘贴到F2和CTRL + Shift + Enter中,然后向下拖动公式,直到客户端名称停止显示)。 You'll want to adjust the columns and rows based on your data. 您需要根据数据调整列和行。 So if your Client data goes from C2:C10000 use that instead of C2:C8. 因此,如果您的客户数据来自C2:C10000,请使用该数据代替C2:C8。 This resulted in: 结果是:

  A       B        C      D     E     F
order   date    client  store       HideMe
1234            Client1 Store1      Client1
6543            Client2 Store1      Client2
5432            Client3 Store2      Client3
3214            Client1 Store3      Client4
9876            Client2 Store2      
8765            Client4 Store5      
7654            Client3 Store3      

Then I highlighted the HideMe list and gave it a name. 然后,我突出显示HideMe列表并为其命名。 I recommend either using a dynamic range named list for easier maintenance down the road. 我建议您使用一个动态范围命名列表,以方便日后的维护。 Otherwise you'll need to come in and alter the named range every time a new client is added to your data. 否则,每次将新客户端添加到数据时,您都需要进入并更改命名范围。 I named my range ClientList 我将范围命名为ClientList

I created a Data Validation Dropdown List with =ClientList which resulted in a dropdown which only has each client listed once. 我用= ClientList创建了一个数据验证下拉列表,这导致一个下拉列表,其中每个客户端仅列出一次。

I put that dropdown in H2. 我将该下拉列表放在H2中。

I then put the following formula in column G to create a list of unique stores based upon the value of our dropdown in H2: =IFERROR(INDEX($D$2:$D$8, MATCH(0, IF($H$2=$C$2:$C$8, COUNTIF($G$1:$G1, $D$2:$D$17), ""), 0)),"") As with the other formula, CTRL+Shift+Enter and replace ranges to facilitate your data structure. 然后,将以下公式放在G列中,以基于H2中下拉列表的值创建唯一存储的列表: =IFERROR(INDEX($D$2:$D$8, MATCH(0, IF($H$2=$C$2:$C$8, COUNTIF($G$1:$G1, $D$2:$D$17), ""), 0)),"")和其他公式一样,CTRL + Shift +输入并替换范围简化您的数据结构。 Drag the formula down for a while. 将公式向下拖动一会儿。 When you populate the dropdown in H2, the list will be dynamically updated so it only contains stores matched with the selected client. 在H2中填充下拉列表时,该列表将动态更新,因此它仅包含与所选客户端匹配的商店。 Create a dynamic named range or select enough of a range in Column G to accommodate your match options and name the range. 创建动态命名范围或在G列中选择足够的范围以容纳您的匹配选项并命名该范围。 I named mine ClientStores. 我将其命名为ClientStores。

In Cell I2 I created my second dropdown list with Data Validation =ClientStores 在单元格I2中,我使用数据验证= ClientStores创建了第二个下拉列表

Then you can hide your columns F and G so you are left with data and your two dropdowns. 然后,您可以隐藏列F和G,以便剩下数据和两个下拉菜单。

客户端下拉列表示例存储下拉示例1商店下拉菜单Example2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM