繁体   English   中英

VBA用于获取由逗号与其他单元格分隔的单元格中的MATCH值

[英]VBA to get MATCH values within a cell separated by comma from other cell

我对VBA相对较新,我希望创建一个MACRO来匹配由逗号与其他单元格分隔的单元格中的值,并告诉结果是否存在匹配项。

输入:

   a                         b             
1 abc ,edr,edd,eee          abc

输出:

   a                         b              c             
1 abc ,edr,edd,eee          abc           Match
2 abc ,edr,edd,eee          eef          No Match 

代码:

Function TRACK(pValue As String, pWorking As Range)
    Dim pValue As String
    Dim xResult As String
    pWorking() = Split(pWorking, ",")
    xResult = " "

    For Each pValue In pWorking
        If pWorking = pValue Then
        xResult =  “ Match”
    else
        xResult = “ No Match”
    Next

    ASSEMBLY = xResult
End Function

将pWorking拆分为数组后,可以使用工作表的Match函数来确定是否包含pValue。

Function TRACK(pValue As String, pWorking As String)

    Dim vals As Variant

    vals = Split(pWorking, ",")

    If IsError(Application.Match(pValue, vals, 0)) Then
        TRACK = "No Match"
    Else
        TRACK = "Match"
    End If

End Function

小心'智能引号(例如“ and ” )。 它们在代码中不是有效的引号。

暂无
暂无

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

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