Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
man818
 
Posts: n/a
Default In Excel, how do I find one word in a set of text in a cell?

I am trying to find all instances of a word in a set of words in a cell.

e.g. The cow jumped over the moon

I want to find all instances of cow.


  #2   Report Post  
Posted to microsoft.public.excel.misc
Barb Reinhardt
 
Posts: n/a
Default In Excel, how do I find one word in a set of text in a cell?

Do you want to know if it's present or how many times it's present in the
cell.

If "The cow jumped over the moon" is in A1 and you want to know if cow is
present in A1, try this:

=IF(ISNUMBER(SEARCH("cow",A1)),"Yes","No")

"man818" wrote:

I am trying to find all instances of a word in a set of words in a cell.

e.g. The cow jumped over the moon

I want to find all instances of cow.


  #3   Report Post  
Posted to microsoft.public.excel.misc
RaymundCG
 
Posts: n/a
Default In Excel, how do I find one word in a set of text in a cell?

Hi!

If I got right it, you wanted to count the number of occurences of a
substring within a string?

In that case, a custom function can be made using VBA which goes like this...

Public Function CountIn(strText As String, strFind As String, _
Optional lngCompare As VbCompareMethod = vbBinaryCompare) As Long

Dim lngCount As Long
Dim lngPos As Long

If Len(strFind) 0 Then
lngPos = 1
Do
lngPos = InStr(lngPos, strText, strFind, lngCompare)
If lngPos 0 Then
lngCount = lngCount + 1
lngPos = lngPos + Len(strFind)
End If
Loop While lngPos 0
Else
lngCount = 0
End If
CountIn = lngCount
End Function

You'll have to place this in a code module in the VBA window (you may access
this by pressing Alt+F11).

Once inputted the syntax of the custom function would now be entered as...

=CountIn(string,substring)

where string = "the cow jumped over the moon" and substring = "cow"

You may try adding "cow" substrings within the string to check.

Hope this helps!

--
Thanks and kind regards


"man818" wrote:

I am trying to find all instances of a word in a set of words in a cell.

e.g. The cow jumped over the moon

I want to find all instances of cow.


  #4   Report Post  
Posted to microsoft.public.excel.misc
RaymundCG
 
Posts: n/a
Default In Excel, how do I find one word in a set of text in a cell?

Additional info:

-String can use the cell address of the original data
-Substring should be enclosed in double quotes
--
Thanks and kind regards


"RaymundCG" wrote:

Hi!

If I got right it, you wanted to count the number of occurences of a
substring within a string?

In that case, a custom function can be made using VBA which goes like this...

Public Function CountIn(strText As String, strFind As String, _
Optional lngCompare As VbCompareMethod = vbBinaryCompare) As Long

Dim lngCount As Long
Dim lngPos As Long

If Len(strFind) 0 Then
lngPos = 1
Do
lngPos = InStr(lngPos, strText, strFind, lngCompare)
If lngPos 0 Then
lngCount = lngCount + 1
lngPos = lngPos + Len(strFind)
End If
Loop While lngPos 0
Else
lngCount = 0
End If
CountIn = lngCount
End Function

You'll have to place this in a code module in the VBA window (you may access
this by pressing Alt+F11).

Once inputted the syntax of the custom function would now be entered as...

=CountIn(string,substring)

where string = "the cow jumped over the moon" and substring = "cow"

You may try adding "cow" substrings within the string to check.

Hope this helps!

--
Thanks and kind regards


"man818" wrote:

I am trying to find all instances of a word in a set of words in a cell.

e.g. The cow jumped over the moon

I want to find all instances of cow.


  #5   Report Post  
Posted to microsoft.public.excel.misc
RaymundCG
 
Posts: n/a
Default In Excel, how do I find one word in a set of text in a cell?

Additional info 2

This custom function is case sensitive; use the ff syntax as applicable:

=CountIn(string,substring,0) for case sensitive substring entries or
=CountIn(string,substring,1) if not case sensitive

--
Thanks and kind regards


"RaymundCG" wrote:

Hi!

If I got right it, you wanted to count the number of occurences of a
substring within a string?

In that case, a custom function can be made using VBA which goes like this...

Public Function CountIn(strText As String, strFind As String, _
Optional lngCompare As VbCompareMethod = vbBinaryCompare) As Long

Dim lngCount As Long
Dim lngPos As Long

If Len(strFind) 0 Then
lngPos = 1
Do
lngPos = InStr(lngPos, strText, strFind, lngCompare)
If lngPos 0 Then
lngCount = lngCount + 1
lngPos = lngPos + Len(strFind)
End If
Loop While lngPos 0
Else
lngCount = 0
End If
CountIn = lngCount
End Function

You'll have to place this in a code module in the VBA window (you may access
this by pressing Alt+F11).

Once inputted the syntax of the custom function would now be entered as...

=CountIn(string,substring)

where string = "the cow jumped over the moon" and substring = "cow"

You may try adding "cow" substrings within the string to check.

Hope this helps!

--
Thanks and kind regards


"man818" wrote:

I am trying to find all instances of a word in a set of words in a cell.

e.g. The cow jumped over the moon

I want to find all instances of cow.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find text within cell then display text to left Jambruins Excel Discussion (Misc queries) 5 April 17th 06 10:01 PM
find number position in excel text cell Don Excel Discussion (Misc queries) 5 April 7th 06 09:34 PM
moving text from a word document to excel gregp22 New Users to Excel 2 March 21st 06 06:18 PM
Wrap text ceases to function in Excel if cell exceeds 9 lines nycemail Excel Worksheet Functions 1 July 24th 05 06:09 PM
Copy Word table into Excel cell by cell hg Excel Discussion (Misc queries) 3 December 15th 04 04:43 PM


All times are GMT +1. The time now is 09:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"