Macro: find a set of words in a string

pennep

New Member
Joined
Apr 7, 2015
Messages
14
Hi,
I am writing a macro which can find if a cell in Column B contains the words in column A. If it does, it writes result in column C.
eg. in the following table, B3 has word 'not' so 'Found' is displayed in C3.
Goal:
ABC
1Look for Look into Result
2notSunday is hot.Not found
3coldMonday is not hot.Found
4winterTuesday is not cold.Found
5likeIt is raining.Not found
6It is neither hot nor cold.Found
7coldFound
8notFound

<tbody>
</tbody>

<tbody>
</tbody>


I manage to write a code that does the task only if cells exactly match. eg B7 and B8.

Sub FindExistance()
Dim ws As Excel.Worksheet
Set ws = ActiveSheet 'assign active sheet to ws
Set objRange = ws.Range("A1").EntireColumn '
i = 1
Do Until ws.Cells(i, 2).Value = ""
strName = ws.Cells(i, 2).Value
Set objSearch = objRange.Find(strName)
If objSearch Is Nothing Then
ws.Cells(i, 3).Value = "Not Found"
Else
ws.Cells(i, 3).Value = "Found"
End If
i = i + 1
Loop
End Sub

I couldn't manage to get it work if only one word match the string. I tried using InStr but couldn't get it done.
Thanks in advance.
P
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You can try a formula instead of a macro

Put in C2
=IF(ISNUMBER(LOOKUP(9.99E+307,SEARCH($A$2:$A$5,B2))),"Found","Not Found")
copy down

Hope this helps

M.
 
Upvote 0
Thank you for the suggestion, but my intention is not to use a formula. My ultimate aim is to list out the words in a separate file and use the script to find those words in another file.
The given example is only to simplify the task.
Anyone?!?
 
Upvote 0

Forum statistics

Threads
1,216,144
Messages
6,129,120
Members
449,488
Latest member
qh017

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