Hi man.
I came with the following code on VBA.
Public Function CheckValues(text As String, range As range)
Dim fila As Integer
fila = 1
Dim regEx As New RegExp
Dim strPattern As String
Dim returns As String
While range(fila, 1).FormulaR1C1 <> ""
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "(\w\s)*" & Change(range(fila, 1).FormulaR1C1) & "(\w\s)*"
End With
If regEx.Test(text) Then
If returns = "" Then
returns = range(fila, 1).Offset(0, 1).FormulaR1C1
Else
returns = returns & ", " & range(fila, 1).Offset(0, 1).FormulaR1C1
End If
End If
fila = fila + 1
Wend
CheckValues = returns
End Function
Public Function Change(entrada As String) As String
entrada = Replace(entrada, "+", "\+")
entrada = Replace(entrada, "?", "[0-9]+")
Change = entrada
End Function
And to call it, you just have to use this on the C column:
=CheckValues(D2,$A$2:$A$52)
The only problem I see is with the string "Restricted" as it is contained in all the strings with Restricted ??
To solve this, is better that you put more values on the list in A (explode 6+ to something like 61,62, 63 and so on)
I used regular expression for Excel, so in order to work with this code, you have to enter in the VBA editor, and in the Tools menu, select "References" then add the reference to "Microsoft VBScript Regular Expressions 5.5".
Another thing that can be improved, is to use an array to save the matches and when a new match is found, check if the value has not been already added.
Check the attached picture for details:
regexp.jpg