简体   繁体   English

Excel - 动态下拉列表

[英]Excel - Dynamic Dropdown List

Looking to make a dynamic dropdown list in a table.希望在表格中制作动态下拉列表。 The photo link below should help visualize the problem.下面的照片链接应该有助于可视化问题。

What I am looking to do is create a dynamic dropdown list in one table using a column from the same table and two columns from a second table in another sheet.我要做的是使用同一张表中的一列和另一张表中第二张表中的两列在一个表中创建一个动态下拉列表。

The column with the dropdown should compare the column to the left of it to right column of the second table.带有下拉列表的列应将其左侧的列与第二个表的右侧列进行比较。 The options in the dropdown should be the values in the left column of the second table if the cell to the left of the dropdown cell equals the cell to the right of the value cell in the second table.|如果下拉单元格左侧的单元格等于第二个表中值单元格右侧的单元格,则下拉列表中的选项应该是第二个表左列中的值。|

The photo below shows the table setups and the numbers next to the top left table show what options that should be in the dropdown.下面的照片显示了表格设置,左上角表格旁边的数字显示了下拉列表中应该包含的选项。

问题示例

Edit: I was looking to do this without using Visual Basic, but I would be open to it if it were the only option.编辑:我希望在不使用 Visual Basic 的情况下做到这一点,但如果它是唯一的选择,我会对此持开放态度。

This is called dependent data validation.这称为相关数据验证。 You need to set up range names.您需要设置范围名称。 One for each reference, and an additional one to resolve the reference into a dropdown using Indirect.每个引用一个,另外一个用于使用 Indirect 将引用解析为下拉列表。 I set up these four range names and for the data validation I used List > =MyDropdown我设置了这四个范围名称,并使用 List > =MyDropdown 进行数据验证

a   =Sheet1!$H$2:$H$5
b   =Sheet1!$H$6:$H$8
cc  =Sheet1!$H$9
MyDropdown  =INDIRECT(Sheet1!$A2)

Note that the reference inside the INDIRECT() function is relative to the cell that was active when the reference is defined.请注意,INDIRECT() function 中的引用相对于定义引用时处于活动状态的单元格。 Select cell in row 2, then create a new named range with that formula.第 2 行中的 Select 单元格,然后使用该公式创建一个新的命名范围。 If you select another cell, this will not work.如果你 select 另一个单元格,这将不起作用。

Note also that the named range cannot be called 'c', so I had to use another reference name.另请注意,命名范围不能称为“c”,因此我必须使用另一个引用名称。

在此处输入图像描述

在此处输入图像描述

As per above data setup put below formula to H6根据上述数据设置,将以下公式放入H6

=TRANSPOSE(UNIQUE(E6:E13))

Then put below formula to H7 cell and drag across right.然后将下面的公式放入H7单元格并向右拖动。

=FILTER($D$6:$D$13,$E$6:$E$13=H$6)

Above formulas will spill data automatically.以上公式将自动溢出数据。 Then in data validation for range A1:A10 put below formula然后在范围A1:A10的数据验证中放入以下公式

=H$6$#

# after H$6$ will take data dynamically output by Unique() formula till last data. # H$6$之后将通过Unique()公式动态获取数据 output 直到最后一个数据。

在此处输入图像描述

Then for range B2:B10 data validation formula will然后对于范围B2:B10数据验证公式将

=INDEX($H$7:$J$10,,MATCH($A1,$H$6#,0))

在此处输入图像描述

Dropdown result下拉结果

在此处输入图像描述

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

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