匹配一个Cell Range中的任何单元格与任何单元格的另一个Cell Range

时间:2015-06-29 14:25:39

标签: excel excel-formula

     Col A     |  Col B    |     Col C    |   Col D |       Col E     |
row1 Roles     |    Create |    Review    | Approve |      Name       |
row2 PM/Dev/IT |     SQA   |   PM/Dev/IT  |  SQA*   |    Ryan (IT)    |
     PM/Dev    |     SQA   |      N/A     |  SQA    |    Casey (SQA)  |
     PM        |     DEV   |       IT     |  PM     |    Shannon (PM) |
     DEV       |        
     IT        |            
     QA        |            
     SQA       |            
row8 SQA*      |                
rw9  SQA**     |                
     Other____ |

rw12 PM        |     CellB13=IF((A13=B2:D2), F4, "N/A")    |        
     SQA       |     CellB14=IF((A13=B2:D2), F5, "N/A")    |
rw13 IT        |     CellB15=IF((A13=B2:D2), F6, "N/A")    |

我希望B13 = YES,如果

如果角色列位于Create / Review / orApprove行,则显示PM值B13 / B14 / B15显示相应单元格中的名称值

我想避免将VBA用于解决方案

1 个答案:

答案 0 :(得分:0)

试试这个小 UDF()

Public Function AnyMatch(r1 As Range, r2 As Range) As String
    Dim v As Variant, r As Range, rTemp As Range
    AnyMatch = "NO"

    For Each r In r1
        v = r.Value
        Set rTemp = r2.Find(What:=v, After:=r2(1), LookAt:=xlPart)
        If rTemp Is Nothing Then
        Else
            AnyMatch = "YES"
            Exit Function
        End If
    Next r
End Function

用户定义函数(UDF)非常易于安装和使用:

  1. ALT-F11调出VBE窗口
  2. ALT-I ALT-M打开了一个新模块
  3. 粘贴内容并关闭VBE窗口
  4. 如果保存工作簿,UDF将随之保存。 如果您在2003年之后使用的是Excel版本,则必须保存 该文件为.xlsm而不是.xlsx

    删除UDF:

    1. 按上述方式调出VBE窗口
    2. 清除代码
    3. 关闭VBE窗口
    4. 从Excel使用UDF:

      =AnyMatch(A1:C1,H1:Z1)
      

      要了解有关宏的更多信息,请参阅:

      http://www.mvps.org/dmcritchie/excel/getstarted.htm

      http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

      有关UDF的详细信息,请参阅:

      http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx

      必须启用宏才能使其生效!