Excel FIND.VERT 关键字表中包含部分文本

Excel FIND.VERT 关键字表中包含部分文本

我需要一个特定的函数,但我认为它在标准 Excel 中不存在,可能需要一个自定义 VBA 函数。

此函数应该执行类似 FIND.VERT 的操作,但通过特定查找来查找目标字符串中的部分文本。

=MYCUSTOM.FIND.VERT(A1;KeyTable!A:B;2;SpecialPartialLookup)

这是目标单元格(?是公式的位置):

+----------------------------------+---+
| Text with some keyword somewhere | ? |
| Another test for this function   | ? |
| I'm not very imaginative now     | ? |
+----------------------------------+---+

以及关键字表:

+------------------+-----------+
|     KEYWORD      |   VALUE   |
+------------------+-----------+
| somewhere        | adverb    |
| test             | noun      |
| very imaginative | adjective |
| very imaginative | dontknow  |
+------------------+-----------+

这就是我要的:

+----------------------------------+-----------+
|               TEXT               | RESULT    |
+----------------------------------+-----------+
| Text with some keyword SOMEWHERE | adverb    |
| Another TEST for this function   | noun      |
| I'm not VERY IMAGINATIVE now     | adjective |
+----------------------------------+-----------+

(大写仅显示匹配)

是否可以?

答案1

这是答案:

Function VerticalMatch(Value As Range, Matrix As Range, Index As Integer) As Variant
    Dim baseText As String
    Dim x As Integer
    x = 0
    baseText = LCase(Value.Item(1).Value)


    For Each cell In Matrix.Columns(1).Cells
        x = x + 1
        If baseText Like LCase(cell.Value) Then
            VerticalMatch = Matrix.Columns(Index).Rows(x).Value
            Exit Function
        End If
    Next

    VerticalMatch = CVErr(xlErrNA)

End Function

其工作原理与 Find.Vert 类似,但使用“类似”比较。

因此输入必须填充通配符:

+--------------------+-----------+
|     KEYWORD        |   VALUE   |
+--------------------+-----------+
| *somewhere         | adverb    |
| *test*             | noun      |
| *very imaginative* | adjective |
| *very imaginative* | dontknow  |
+--------------------+-----------+

相关内容