QUESTION :
I need a particular function and I think that it doesn’t exists in standard Excel and probably I need a custom VBA function.
This function should do something like FIND.VERT but with particlular lookup to find partial text in the target string.
=MYCUSTOM.FIND.VERT(A1;KeyTable!A:B;2;SpecialPartialLookup)
This is the target cells (? is the place of the formula):
+----------------------------------+---+
| Text with some keyword somewhere | ? |
| Another test for this function | ? |
| I'm not very imaginative now | ? |
+----------------------------------+---+
and a keyword table:
+------------------+-----------+
| KEYWORD | VALUE |
+------------------+-----------+
| somewhere | adverb |
| test | noun |
| very imaginative | adjective |
| very imaginative | dontknow |
+------------------+-----------+
This is what I want:
+----------------------------------+-----------+
| TEXT | RESULT |
+----------------------------------+-----------+
| Text with some keyword SOMEWHERE | adverb |
| Another TEST for this function | noun |
| I'm not VERY IMAGINATIVE now | adjective |
+----------------------------------+-----------+
(uppercase is only to show the match)
Is it possible?
ANSWER :
This is the answer:
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
This works like Find.Vert but using a “like” comparison.
So the input has to be filled with wildcards:
+--------------------+-----------+
| KEYWORD | VALUE |
+--------------------+-----------+
| *somewhere | adverb |
| *test* | noun |
| *very imaginative* | adjective |
| *very imaginative* | dontknow |
+--------------------+-----------+