[翻译]  Combine list and custom formula data validation in one cell within excel without vba

[CHINESE]  在excel中的一个单元格中组合列表和自定义公式数据验证,而无需vba


Can anyone help with a way of combining list and custom formula data validation in a single cell without using vba? I have a custom formula which validates the data if logical is TRUE but I want the user to have ability as well to select from a drop down list. Any assistance will be appreciated. Thanks.

任何人都可以帮助在不使用vb​​a的情况下在单个单元格中组合列表和自定义公式数据验证的方法吗?我有一个自定义公式,如果逻辑为TRUE,则验证数据,但我希望用户也有能力从下拉列表中进行选择。任何帮助将不胜感激。谢谢。

Sorry if the question wasn't so clear enough. Please see below:

对不起,如果问题不够清楚。请看下面:

enter image description here

In this example, even though the user is able select from a dropdown list, if the user selects 7 for cell A2, the validation should throw out an error because it is not less than or equal to cell B2. Is it clearer?

在此示例中,即使用户能够从下拉列表中进行选择,如果用户为单元格A2选择7,则验证应该抛出错误,因为它不小于或等于单元格B2。它更清楚吗?

3 个解决方案

#1


3  

This non-VBA solution combines a conditional with a dropdown picklist. It provides 2 different picklists, dependent on value in another column.

这种非VBA解决方案将条件与下拉选项列表相结合。它提供了2个不同的选项列表,取决于另一列中的值。

This is different than the oft-shared cascading-lists method (but do see the link for some great techniques)

这与经常共享的级联列表方法不同(但确实看到了一些很棒的技术链接)

Let's say you have a table with two columns. Field1 may contain anything:

假设你有一个包含两列的表格。 Field1可能包含任何内容:

a
box
cat
z

Requirement: Field2's validation should display List1 dropdown list when Field1 contains a, and display List2 when Field1 contains anything else.

要求:当Field1包含a时,Field2的验证应显示List1下拉列表,当Field1包含其他任何内容时,显示List2。

Solution: Relies on the fact that an Excel conditional formula can return a range containing a list of items.

解决方案:依赖于Excel条件公式可以返回包含项列表的范围这一事实。

Steps:

脚步:

  • Create a list of picklist-values on a lookup-sheet, and name it List1.
  • 在查找表上创建一个picklist-values列表,并将其命名为List1。
  • Create another list on the lookup-sheet, and name it List2.
  • 在查找表上创建另一个列表,并将其命名为List2。
  • On your entry-sheet, insert a Table object containing 2 columns. Name the table MyTable, and the fields Field1 and Field2.

    在条目表上,插入包含2列的Table对象。将表命名为MyTable,并将字段命名为Field1和Field2。

    enter image description here

  • Create the following defined name, and call it ValidFmla. This is the secret sauce:

    创建以下定义的名称,并将其命名为ValidFmla。这是秘诀:

    =IF(MyTable[@Field1]="a", List1, List2)

    = IF(MyTable [@ Field1] =“a”,List1,List2)

  • Select the entry-cells in Field2, and click Validation on the data-ribbon.

    在Field2中选择条目单元格,然后单击数据功能区上的验证。

  • Choose "List" type, and enter =ValidFmla
  • 选择“列表”类型,然后输入= ValidFmla
  • test it out:

    测试出来:

    enter image description hereenter image description here

Benefits:

优点:

  • It will not break if you change your table name, field names, list-names, or validation-formula name-- all dependent stuff updates automatically.

    如果您更改表名,字段名,列表名或验证公式名称,它将不会中断 - 所有依赖项自动更新。

  • supports any complex conditions you want, as long as your validation formula returns a list-range. Validation does not have to be based on the values in Field1.

    只要您的验证公式返回列表范围,就可以支持您想要的任何复杂条件。验证不必基于Field1中的值。

  • the validation list-ranges can be named anything. the dependent-lists method requires naming the validation list-ranges the same as the values in the first field.

    验证列表范围可以命名为任何名称。 dependent-lists方法需要命名验证列表范围与第一个字段中的值相同。

Note, you do not have to use a Table object to use this method. But, using the Table object provides structured-referencing in the validation formula, which is a smarter, more readable way to build formulas.

请注意,您不必使用Table对象来使用此方法。但是,使用Table对象在验证公式中提供了结构化引用,这是一种更智能,更易读的构建公式的方法。

#2


1  

Save we want to setup DV in cell B1 so:

保存我们要在单元格B1中设置DV,以便:

  • if a number is entered, it must be less than the value in A1
  • 如果输入数字,则必须小于A1中的值
  • if text is entered, it must be in the list from D1 throughD3
  • 如果输入文本,则它必须位于D1到D3的列表中

Here is the formulaic DV to do that:

这是公式化的DV:

enter image description here

The formula combines numeric tests with the ability to restrict input to some fixed list.

该公式将数字测试与将输入限制为某个固定列表的能力相结合。

#3


0  

I know this thread is older, but for completeness I am also going to offer another solution that is non-VBA. The OP I don't believe was seeking methods to provide dependent lists as per most of the solutions offered, instead he wants his options list to exist as-is and instead provide additional validation on the actual selection being performed.

我知道这个线程较旧,但为了完整性,我还将提供另一个非VBA的解决方案。 OP我不相信正在寻求根据提供的大多数解决方案提供依赖列表的方法,而是他希望他的选项列表按原样存在,而是对正在执行的实际选择提供额外的验证。

This actually needs to use a different feature of Excel to provide this insight to yourself easier. Conditional Formatting. As per the OP's screenshot provided originally:

这实际上需要使用Excel的不同功能来更轻松地为您提供这种洞察力。条件格式。根据最初提供的OP截图:

Highlight column A, click Conditional Formatting (Home Tab for me) > New Rule. Select the last option, custom formula one, and use the formula:

突出显示A列,单击条件格式(对我来说是主页选项卡)>新规则。选择最后一个选项,自定义公式1,然后使用公式:

=$A1>$B1

Click Formatting button, change the background or some other colouring so the validation is made obvious, click OK. See screenshot for results, you still setup your data validation list as per normal for the user to select values from. One thing to note, is that this does not stop the input, it merely provides a visual confirmation that the input is wrong.

单击“格式”按钮,更改背景或其他颜色以使验证变得明显,单击“确定”。查看结果的屏幕截图,您仍然按照正常情况设置数据验证列表,以便用户从中选择值。需要注意的一点是,这不会停止输入,它只是提供输入错误的视觉确认。

Screenshot of results

结果截图


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号