匹配单元格内的任何单词与单元格范围内的任何单词

我有一个短语列表。 我想检查是否有新的条款部分匹配的单词。

我正在寻找一个代码来实现列表上的模糊匹配,以返回具有紧密匹配的单元格。

示例数据:

在这里输入图像说明

Phrases,Terms real term,new words great work,new term check phrase,more phrase example here,great alpha phrase random,beta new 

期望的输出:

在这里输入图像说明

 Phrases,Term,Match real term,new words,No match great work,new term,real term check phrase,more phrase,check phrase/phrase random example here,great alpha,great work phrase random,beta new,No match 

我得到了什么:

我尝试使用下面的代码来匹配单元格,如果它被发现:

 =IF(ISERROR(MATCH("*" & B2 & "*",A:A, 0)), "No Match", VLOOKUP("*" & B2 & "*",A:A,1,FALSE)) 

但是,代码只匹配整个单元格。 我怎样才能使它匹配单元格中的任何单词? 这将创build一个模糊的匹配。 任何积极的投入是高度赞赏。

这是一个(粗糙和准备好)VBA解决scheme,以您的问题。 您需要将其插入到VBA编辑器中的代码模块中,然后才能运行macros以获得所需的输出

 Sub FindSimilar() Dim phrases As Range, phrase As Range Dim terms As Range, term As Range Dim matches As String Dim words() As String 'ensure this has the correct sheet names for your workbook Set phrases = ThisWorkbook.Worksheets("Sheet2").Range("A2:A6") Set terms = ThisWorkbook.Worksheets("Sheet1").Range("D2:D6") For Each term In terms matches = vbNullString words() = Split(term.Value) For i = 0 To UBound(words, 1) For Each phrase In phrases If InStr(1, phrase.Value, words(i)) Then matches = matches & phrase & "/" End If Next phrase Next i If matches <> vbNullString Then term.Offset(0, 5).Value = Left(matches, Len(matches) - 1) Else term.Offset(0, 5).Value = "No match" End If Next term End Sub