Excel search for multiple text strings in a cell

weasel_girl

New Member
Joined
Sep 12, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a data from a survey and I would like to look up whether a cell contains specific answer keys and then return an appropriate response.

In the example below, I want to look in the Data column, if the data cell contains "F1" AND "F2" AND "F3" then the response column would be "Yes", otherwise the response should be "No". I'm stuck on how to construct the AND statement to use with the search function. Help gratefully appreciated!



DataResponse
F1 - v56; F2 - v59; F3 - t66Yes
F1 - v56; F2 - v59; F3 - t66Yes
F1 - v56; F2 - v59No
F3 - t66No
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Book1
ABC
1DataResponse
2F1 - v56; F2 - v59; F3 - t66YesYes
3F1 - v56; F2 - v59; F3 - t66YesYes
4F1 - v56; F2 - v59NoNo
5F3 - t66No
Sheet1
Cell Formulas
RangeFormula
C2:C5C2=IF(SUMPRODUCT(--ISNUMBER(SEARCH({"F1","F2","F3"},A2)))=3,"Yes","No")
 
Upvote 0
Solution
How about
VBA Code:
Sub test()
    Dim a As Variant: Dim i&
    a = Sheets("Sheet1").Range(Cells(1.1), Cells(1, 1).End(xlDown).Cells)
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "[(FFF)]."
        For i = 2 To UBound(a)
            If .Execute(a(i, 1)).Count = 3 Then:  a(i, 1) = "Yes": Else a(i, 1) = "NO"
        Next
    End With
    a(1, 1) = "Response"
    Cells(1, 2).Resize(UBound(a)) = a
End Sub
 
Upvote 0
A possible option, with formula:
-in B1 insert the keys to be checked
-in B2 insert the formula
Excel Formula:
=LET(ckNum,SUBSTITUTE(SUBSTITUTE($A2,"-"," "),";"," ")&" ",mNum,B$1,mbits,TEXTSPLIT(mNum,," "),IF(SUM(--ISNUMBER(SEARCH(mbits&" ",ckNum)))=COUNTA(mbits),"Yesss","No"))
Copy to the right, for as many cells have been filled with keys
Then copy the first line of formulas down

Results as in the following example:
Cartel1
ABCDEF
1DataF1 F2 F3 F2 F1F t66C5J3
2F1 - v56; F2 - v5; F3 - t66YesssYesssNoNoNo
3F1 - v56; F2 - v59; F3 - t66YesssYesssNoNoNo
4F1 - v56; F2 - v59NoYesssNoNoNo
5F3 - t66NoNoNoNoNo
6FA C55 H2 J3NoNoNoNoYesss
7F1 ZZ;F2;BB;C5NoYesssNoYesssNo
Foglio2
Cell Formulas
RangeFormula
B2:F7B2=LET(ckNum,SUBSTITUTE(SUBSTITUTE($A2,"-"," "),";"," ")&" ",mNum,B$1,mbits,TEXTSPLIT(mNum,," "),IF(SUM(--ISNUMBER(SEARCH(mbits&" ",ckNum)))=COUNTA(mbits),"Yesss","No"))
 
Upvote 0
Book1
ABC
1DataResponse
2F1 - v56; F2 - v59; F3 - t66YesYes
3F1 - v56; F2 - v59; F3 - t66YesYes
4F1 - v56; F2 - v59NoNo
5F3 - t66No
Sheet1
Cell Formulas
RangeFormula
C2:C5C2=IF(SUMPRODUCT(--ISNUMBER(SEARCH({"F1","F2","F3"},A2)))=3,"Yes","No")
Thank you - this worked perfectly.

Thanks for the other suggestions too - I may need to extend this in the future so it will be very useful.
 
Upvote 0
Another short formula option would be

22 09 13.xlsm
AB
1DataResponse
2F1 - v56; F2 - v59; F3 - t66Yes
3F1 - v56; F2 - v59; F3 - t66Yes
4F1 - v56; F2 - v59No
5F3 - t66No
Yes No
Cell Formulas
RangeFormula
B2:B5B2=IF(COUNT(FIND({"F1","F2","F3"},A2))=3,"Yes","No")
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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