简体   繁体   English

在没有VBA的情况下更新excel中的动态下拉列表

[英]Update dynamic drop-down list in excel without VBA

I want to create 2 dependent drop-down lists in excel, first drop-down value decides what value has to be displayed for the second dropdown.我想在excel中创建2个相关下拉列表,第一个下拉值决定第二个下拉列表必须显示的值。

Used following OFFSET formula for second dropdown values to get populated dynamically.使用以下 OFFSET 公式获取第二个下拉值以动态填充。

=OFFSET($B$2,MATCH($G$3,$B$3:$B$17,0),1,COUNTIF($B$3:$B$17,$G$3),1) =OFFSET($B$2,MATCH($G$3,$B$3:$B$17,0),1,COUNTIF($B$3:$B$17,$G$3),1)

. . I have also prepared a sample file showcasing the formulas I have used.我还准备了一个示例文件,展示了我使用过的公式。

When I select first dropdown value, second dropdown list gets updated.当我选择第一个下拉值时,第二个下拉列表会更新。 BUT, when I select another value in first dropdown, second list doesn't showcase the values immediately.但是,当我在第一个下拉列表中选择另一个值时,第二个列表不会立即显示这些值。

Sample file link - https://drive.google.com/file/d/1rwt6B-INgrQ0NgxIl-Nc8JeoGziBaiL2/view?usp=sharing示例文件链接 - https://drive.google.com/file/d/1rwt6B-INgrQ0NgxIl-Nc8JeoGziBaiL2/view?usp=sharing

Now that's what I call a challenging request.这就是我所说的具有挑战性的请求。
We will use the secret Evaluate formula to achieve this.我们将使用秘密的Evaluate公式来实现这一点。

Disclaimer:免责声明:

  • Ensure that a status never get separated from its peers (eg do not add another New at the end of the table, rather insert a column so that statuses stay in packs).确保状态永远不会与其同级分开(例如,不要在表的末尾添加另一个 New,而是插入一列以便状态保持在包中)。
  • Note that changing status will not clear the definition cell.请注意,更改状态不会清除定义单元格。 Simple VBA will do the trick (and that is the only place where you will need VBA).简单的 VBA 可以解决问题(这是唯一需要 VBA 的地方)。

Solution:解决方案:

  1. Let's create a formula that returns a the address of the range we want to use in the dropdown.让我们创建一个公式,该公式返回我们要在下拉列表中使用的范围的地址 You can paste that it I3.你可以粘贴它I3。
    =ADDRESS(ROW(OFFSET($C$2,MATCH($G3,$B$3:$B$17,0),0)), COLUMN($C$2)) & ":" & ADDRESS(ROW(OFFSET($C$2,MATCH($G3,$B$3:$B$17,0)+COUNTIF($B$3:$B$17,$G3)-1,0)),COLUMN($C$2))
    If I made no mistake with my French Excel, you should get the address of all the definitions for the status you put in G3.如果我的法语 Excel 没有弄错,你应该会得到你在 G3 中放置的状态的所有定义的地址。 Extend the formula a few rows down and you will see it always matches G4, G5 and so on.将公式向下扩展几行,您将看到它始终与 G4、G5 等匹配。

  2. Time to define a Name (Menu Formula > Name manager > New), that we will call DynamicRange.是时候定义一个名称(菜单公式 > 名称管理器 > 新建),我们将称之为 DynamicRange。
    First, I would recommend to change the scope to your worksheet (Dropdown in the window).首先,我建议将范围更改为您的工作表(窗口中的下拉菜单)。
    Next, put the very formula we tried before, but in an EVALUATE .接下来,将我们之前尝试过的公式放在EVALUATE
    =EVALUATE(ADDRESS(ROW(OFFSET($C$2,MATCH($G3,$B$3:$B$17,0),0)), COLUMN($C$2)) & ":" & ADDRESS(ROW(OFFSET($C$2,MATCH($G3,$B$3:$B$17,0)+COUNTIF($B$3:$B$17,$G3)-1,0)),COLUMN($C$2)))

Here what it looks like (except I'm all in French ...)这是它的样子(除了我都是法语......) 已创建新范围

  1. Go back to data validation and in the list's source, simply type =DynamicRange返回数据验证并在列表的源中,只需键入=DynamicRange

The list is easy to define once the above was done successfully.成功完成上述操作后,该列表很容易定义。 列表的定义

I see what you are trying to accomplish (get the second cell value to auto update to the first list entry), but I do not think it is possible without using VBA.我知道您要完成什么(获取第二个单元格值以自动更新到第一个列表条目),但我认为不使用 VBA 是不可能的。

My understanding is that "Data Validation" only verifies the data within the cell, it does not change the existing value.我的理解是“数据验证”仅验证单元格内的数据,它不会更改现有值。

If you want to change the existing value, then I would look into VBA.如果您想更改现有值,那么我会查看 VBA。

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

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