简体   繁体   English

来自常规表的 Excel 相关下拉列表

[英]Excel dependent drop-down list from regular table

Please excuse me if this has been answered already in other posts but I looked forever for this and could not find my scenario.如果已经在其他帖子中回答了这个问题,请原谅我,但我一直在寻找这个并且找不到我的场景。 All the example I found involved static lists but I have a table that will have new entries added.我发现的所有示例都涉及静态列表,但我有一个表,其中将添加新条目。 I have a table with 4 columns as shown below.我有一个包含 4 列的表格,如下所示。

在此处输入图片说明

I want to create two drop downs where the first drop down is for selecting the customer name, and the second drop down is for selecting one of the 3 addresses for that particular customer.我想创建两个下拉列表,其中第一个下拉列表用于选择客户名称,第二个下拉列表用于选择该特定客户的 3 个地址之一。 I created an Excel table for all the data called "TBL_CUST" and then I defined a named range called "Customer" which is based on the first column of the table so the RefersTo value for the named range is "=TBL_CUST[Name]".我为所有名为“TBL_CUST”的数据创建了一个 Excel 表,然后我定义了一个名为“Customer”的命名范围,它基于表的第一列,因此命名范围的 RefersTo 值为“=TBL_CUST[Name]” . I am using that for the data validation for the first drop-down and that's working fine.我将它用于第一个下拉列表的数据验证,并且工作正常。

So now what I need to do is create a second drop down that is dependent on the value selected on the first drop down and then offer just the values for the 3 other columns of that same record.所以现在我需要做的是创建第二个下拉列表,该下拉列表取决于在第一个下拉列表中选择的值,然后仅提供同一记录的其他 3 列的值。 This should not be difficult at all but I have struggled searching on how to do this with no success.这应该不难,但我一直在努力寻找如何做到这一点,但没有成功。 How can I setup a second validation to accomplish this?如何设置第二个验证来完成此操作? I tried using a combination of indirect and vlookup but nothing worked.我尝试使用间接和 vlookup 的组合,但没有任何效果。

A bonus would be clearing out the second drop down field when a value is selected in the first drop down :-)当在第一个下拉列表中选择一个值时,奖励将清除第二个下拉字段:-)

Ok here's how I would go about it.好的,这就是我将如何去做。 Let's say your data is in a2:d8 and your first dropdown is in a12.假设您的数据在 a2:d8 中,而您的第一个下拉列表在 a12 中。 I would create another column (which you can hide or put on a different sheet) which uses this formula starting in row 2. You can then make the second dropdown data validation reference this new column.我将创建另一列(您可以将其隐藏或放在不同的工作表上),它从第 2 行开始使用此公式。然后您可以使第二个下拉数据验证引用此新列。

Formula for E2: E2 的公式:

=INDEX($A$2:$D$8,MATCH($A$12,$A$2:$A$8,0),ROW())

在此处输入图片说明

The template I created by adding dependent drop-down lists on the userform may be useful for you.我通过在用户表单上添加相关下拉列表创建的模板可能对您有用。

Visit enter link description here访问在这里输入链接描述

在此处输入图片说明

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

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