Check whether certain words is contained within a string from a list

HotNumbers

Well-known Member
Joined
Feb 14, 2005
Messages
732
Hello,
I need help. Need to Check cells with string of words separated by semicolon. The cell is checked against a master list of words on a another tab.

Example

Cell A1

APPLE;PAIR;TREE;GREEN;ORANGE;HAPPY

DATA TABLE

APPLE
ORANGE
PAIR


Expected Results based on the master table match
Cell B1
APPLE;PAIR;ORANGE
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hey HotNumbers,

This is a UDF (User Defined Function) which should do what you need. It has 3 arguments first being the text you need to search, 2nd is the range of words you are looking from, and the 3rd argument is optional (can be ignored) which is case sensitive - default is it's not case sensitive, if you need it case sensitive either put 'True' or 1 for the 3rd argument of the function. You can see how it works in the below example

Code:
Option Base 1
Function FindMatches(Txt As String, Rg As Range, Optional CaseSensative As Boolean) As String
Dim Dict As Object, Ar1() As Variant, Ar2() As Variant, Ar3() As String, Cnt As Long
Set Dict = CreateObject("Scripting.Dictionary")
If CaseSensative = False Then Dict.CompareMode = vbTextCompare
Ar1 = Rg
For i = LBound(Ar1) To UBound(Ar1)
    If Not Dict.exists(Ar1(i, 1)) Then Dict.Add Ar1(i, 1), Nothing
Next i
Ar3 = Split(Txt, ";")
For i = LBound(Ar3) To UBound(Ar3)
    If Dict.exists(Ar3(i)) Then
        Cnt = Cnt + 1
        ReDim Preserve Ar2(Cnt)
        Ar2(Cnt) = Ar3(i)
    End If
Next i
FindMatches = Join(Ar2, ";")
End Function


Book1
ABCD
1Original TextUDF OutputLookUp Data
2APPLE;PAIR;TREE;GREEN;ORANGE;HAPPYAPPLE;PAIR;ORANGEAPPLE
3PLANE;HOUSE;BOAT;carPLANEORANGE
4PAIR
5CAR
6Boat
7PLANE
Sheet1
Cell Formulas
RangeFormula
B2=FindMatches(A2,$D$2:$D$7)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top