Find a word in a cell

DeltekJJ

New Member
Joined
Dec 1, 2005
Messages
8
I am writing a macro that requires me to look in a cell. In that cell there will be a string of text. In that text I am looking for a word. If that word is found I want it to return a 1. If not return a 0. For example if I am looking for the word "the" and it looks to cell A1. In A1 is the phrase "I like cake." It will return a zero. Then in Cell A2 is the phrase, "The eggs are the first ingrediant." it will return a 1. How do I do this?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Don't know if it's exactly what you want but you could give this formula a try

=IF(ISERR(SEARCH("*the word*",A1)),0,1)
 
Upvote 0
You can try something like this...<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Test()<SPAN style="color:#00007F">Dim</SPAN> WorkRange<SPAN style="color:#00007F">As</SPAN> Range<SPAN style="color:#00007F">Set</SPAN> WorkRange = Range("B1:B" & Range("A65536").End(xlUp).Row)<SPAN style="color:#00007F">For</SPAN><SPAN style="color:#00007F">Each</SPAN> Cell<SPAN style="color:#00007F">In</SPAN> WorkRange
    <SPAN style="color:#00007F">If</SPAN> UCase(Cell.Offset(0, -1).Value)<SPAN style="color:#00007F">Like</SPAN> "*" & "THE" & "*"<SPAN style="color:#00007F">Then</SPAN>
        Cell.Value = 1
    <SPAN style="color:#00007F">Else</SPAN>
        Cell.Value = 0
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Next</SPAN> Cell<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Sub</SPAN></FONT>

Here is the sample I used....
Book1
ABCD
1StringResult
2I like cake, a lot0
3The eggs are first.1
4Top of the morning.1
5What the?1
6How are you doing?0
Sheet1
 
Upvote 0
Code:
Option Compare Text

Public Sub Demo()
    MsgBox ContainValue(Range("A1").Value, "*The*")
End Sub

Public Function ContainValue(CellValue, ComparValue) As Integer
If CellValue Like ComparValue Then
    ContainValue = 1
Else
    ContainValue = 0
End If
End Function
 
Upvote 0

Forum statistics

Threads
1,214,492
Messages
6,119,866
Members
448,921
Latest member
Ldoot123

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