Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用excel vba验证与一组值匹配的列中的值_Vba_Excel_Validation - Fatal编程技术网

如何使用excel vba验证与一组值匹配的列中的值

如何使用excel vba验证与一组值匹配的列中的值,vba,excel,validation,Vba,Excel,Validation,请参见以下两张图片第1页和第2页 表1 第2页 我试图验证工作表1“颜色”列中的值,也就是说,如果工作表1“类型”为car,则颜色只能是黑色和白色。工作表2有什么类型的规则,哪些颜色可以有效。如果活页1中的Car类型有任何其他颜色,则相邻列应显示“颜色不匹配” 谁能告诉我如何在excel VB中实现这一点 另外,我知道如何使用countifs来实现这一点,但我只想知道如何在Excel VB中实现这一点 多谢各位 您不需要VBA。可以在sheet1单元格E2中使用简单公式(并向下拖动): COU

请参见以下两张图片第1页和第2页

表1

第2页

我试图验证工作表1“颜色”列中的值,也就是说,如果工作表1“类型”为car,则颜色只能是黑色和白色。工作表2有什么类型的规则,哪些颜色可以有效。如果活页1中的Car类型有任何其他颜色,则相邻列应显示“颜色不匹配”

谁能告诉我如何在excel VB中实现这一点

另外,我知道如何使用countifs来实现这一点,但我只想知道如何在Excel VB中实现这一点


多谢各位

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


COUNTIFS和条件格式规则应该能够轻松地完成这项工作。
    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"
=IF(COUNTIFS(Sheet2!$A$1:$A$1000,Sheet1!D2,Sheet2!$C$1:$C$1000,Sheet1!A2)=0,"color not matching","color OK")