【问题标题】:How to validate values in a column matching a set of values using excel vba如何使用excel vba验证与一组值匹配的列中的值
【发布时间】:2017-04-25 12:50:06
【问题描述】:

请看下面两张图片 Sheet 1 和 Sheet 2

表 1

表 2

我正在尝试验证工作表 1“颜色”列中的值,即如果工作表 1“类型”是汽车,那么颜色只能是黑白。工作表 2 有什么类型的规则,哪些颜色可以有效。如果表格 1 中有任何其他颜色用于类型 Car,则相邻列应显示“颜色不匹配”。

    for each cell in (sheet 1 - column color) 
     get type from (sheet 1 - column Type)
    check if (Sheet 1 - column Type) is in (sheet 2 column Type), 
if not give error in adjacent cell "No type"
    if (Sheet 1 - column Type) is in (sheet 2 column Type) then 
Check if (Sheet 1 - column color) has the valid color
 if not give error "color not matching"

谁能告诉我如何在 excel VB 中做到这一点。

P.s,我知道如何使用 countifs 来做到这一点,但只是想知道如何在 Excel VB 中做到这一点

谢谢。

【问题讨论】:

  • COUNTIFS 和条件格式规则应该能够轻松做到这一点。

标签: vba excel validation


【解决方案1】:

您不需要 VBA。您可以在 sheet1 单元格 E2 中使用简单的公式(并向下拖动):

=IF(COUNTIFS(Sheet2!$A$1:$A$1000,Sheet1!D2,Sheet2!$C$1:$C$1000,Sheet1!A2)=0,"color not matching","color OK")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 2020-01-07
    相关资源
    最近更新 更多