Find word in list

moscott75

New Member
Joined
Jan 17, 2008
Messages
25
i have two columns. If a word or words in the world list is found in the text string in column A, I want to put found in the adjacent cell or not found. I want to be able to drag cursor down column C.

ABC
Statement Word List
Dog jumped over the moon.Jumped
It is a good day.Good
200 Mountain Street street
I am glad it's Friday.am glad
I love pizza. I love
Dell laptop Sonya
Results
Dog jumped over the moon.found
It is a good day.found
200 Mountain Street found
I am glad it's Friday.found
I love pizza. found
Dell laptop Not found

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: right"][/TD]

[TD="align: center"]3[/TD]

[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"][/TD]

[TD="align: center"]11[/TD]

[TD="align: right"][/TD]

[TD="align: center"]12[/TD]

[TD="align: right"][/TD]

[TD="align: center"]13[/TD]

[TD="align: right"][/TD]

[TD="align: center"]14[/TD]

[TD="align: right"][/TD]

[TD="align: center"]15[/TD]

[TD="align: right"][/TD]

</tbody>
Sheet1
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Here's a UDF you can try. In B2 enter: =FindWord(A2) and copy down.

To install the UDF:
1. With your workbook active press Alt and F11 keys. This will open the VBE window.
2. In the project tree on the left of the VBE window, find your project and click on it.
3. On the VBE menu: Insert>Module
4. Copy the UDF from your browser window and paste it into the white space in the VBE window.
5. Close the VBE window and Save the workbook. If you are using Excel 2007 or a later version do a SaveAs and save it as a macro-enabled workbook (.xlsm file extension).
6. Use the UDF as you would any native Excel function.
7. Make sure you have enabled macros whenever you open the file or the code will not run.
Code:
Function FindWord(S As String) As String
Dim Wrds As Variant, Parts As Variant, i As Long, j As Long

If S = "" Then
       FindWord = ""
       Exit Function
End If
Wrds = Split(Join(Application.Transpose(Range("C2:C" & Cells(Rows.Count, "C").End(xlUp).Row)), " "))
S = Replace(S, ".", "") 'if there will be other punctuation marks, add remove them in similar fashion
Parts = Split(S, " ")
For i = LBound(Parts) To UBound(Parts)
       For j = LBound(Wrds) To UBound(Wrds)
              If LCase(Parts(i)) = LCase(Wrds(j)) Then
                     FindWord = "found"
                     Exit Function
              End If
       Next j
Next i
FindWord = "Not found"
End Function
 
Upvote 0
wouldn't you simply use ....

=IF(ISNUMBER(SEARCH(C2,A2))=TRUE,"Found","Not Found")

Kind regards,

Chris
 
Upvote 0
wouldn't you simply use ....

=IF(ISNUMBER(SEARCH(C2,A2))=TRUE,"Found","Not Found")

Kind regards,

Chris
That works for the OP's example, but the request is" "If a word or words in the world list is found in the text string ...." so seems any word in the word list might appear in any cell in col A in the general case.
 
Upvote 0
That works for the OP's example,
To be honest, I don't think the post #3 formula even works for that. For example, change the C2 value to the word "on". The suggested formula returns "Found" when the word 'on" does not appear in A2.

@moscott75
It would be good to clarify further just what you want. What would be the expected results for the below sample, column D, column E or something else?
Could you also please clarify whether I am right or wrong about the "on" example above.


Book1
ABCDE
1StatementWord ListCheck ColumnCheck Row
2Dog jumped over the moon.GoodFoundNot found
3It is a good day.moonFoundNot found
4200 Mountain StreetstreetFoundFound
5I am glad it's Friday.I loveFoundNot found
6I love pizza.am gladFoundNot found
7Dell laptopSonyaNot foundNot found
Word in list (2)
 
Last edited:
Upvote 0
Column D is correct. If the words in the word list are found in column A string, I wanted the results to say "found".
 
Upvote 0
Here is another UDF (user defined function) that you can try...
Code:
[table="width: 500"]
[tr]
	[td]Function FindWord(S As String) As String
  Dim W As Variant, Words As Variant
  [B][COLOR="#FF0000"]Application.Volatile[/COLOR][/B]
  If S = "" Then Exit Function
  FindWord = "Not Found"
  Words = Range("C2", Cells(Rows.Count, "C").End(xlUp))
  For Each W In Words
    If " " & UCase(S) & " " Like "*[!A-Z]" & UCase(W) & "[!A-Z]*" Then
      FindWord = "Found"
      Exit For
    End If
  Next
End Function[/td]
[/tr]
[/table]

Note: I made the function volatile so that it will react to changes in the word list. If the list is fixed and won't ever be changed, you can comment out the red highlighted line of code.


HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use FindWord just like it was a built-in Excel function. For example,

=FindWord(A1)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Last edited:
Upvote 0
Here is a standard worksheet formula that seems to do what you need for the type of sample data provided so far.


Book1
ABCD
1StatementWord ListResult
2Dog jumped over the moon.GoodFound
3It is a good day.moonFound
4200 Mountain StreetstreetFound
5I am glad it's Friday.I loveFound
6I love pizza.am gladFound
7Dell laptopSonyaNot found
Sheet1
Cell Formulas
RangeFormula
D2=IF(IFERROR(AGGREGATE(14,6,SEARCH(" "&$C$2:$C$7&" "," "&SUBSTITUTE(A2,".","")&" "),1),0),"Found","Not found")



However, you did not answer my question about the "on" example discussed above. To clarify, what should the results be for this sample data, given that neither item in column C exists as a whole "word" in column A but both exist within the column A "text"?


Book1
ABC
2Dog jumped over the moon.it
3I am glad it's Friday. on
Sheet2
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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