Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JT JT is offline
external usenet poster
 
Posts: 234
Default find text in a string

I'm looking for a suggestion or code on finding text within a string.

For example, I have a field in an Excel spreadsheet that contains a
description of a user issue.

I want to categorize these descriptions by finding a specific word in the
description, e.g., claim, lawsuit, refund, etc. These specific words are
supposed to appear at the beginning of the description but users may place
them anywhere in the description.

I thought of doing using the 'mid' and cycling through the description but
that doesn't seem to be a very efficient way to validate whether a specific
word appears in the description.

Thanks for the help...


--
JT
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default find text in a string

Assuming we are talking about VB code (since you posted in a programming
newsgroup and also used the keyword "Mid")... you can use the InStr function
which returns the position within a larger text string where the text you
are searching for is located. Since you have multiple words to search for,
then you will need to loop through your keywords as you loop through your
cells.

--
Rick (MVP - Excel)


"JT" wrote in message
...
I'm looking for a suggestion or code on finding text within a string.

For example, I have a field in an Excel spreadsheet that contains a
description of a user issue.

I want to categorize these descriptions by finding a specific word in the
description, e.g., claim, lawsuit, refund, etc. These specific words are
supposed to appear at the beginning of the description but users may place
them anywhere in the description.

I thought of doing using the 'mid' and cycling through the description but
that doesn't seem to be a very efficient way to validate whether a
specific
word appears in the description.

Thanks for the help...


--
JT


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default find text in a string

Say we are searching for "happiness". Try this:

Sub FindIt()
Dim s As String
s = "happiness"
For Each r In ActiveSheet.UsedRange
v = r.Value
l = Len(v)
v2 = Application.WorksheetFunction.Substitute(v, s, "")
l2 = Len(v2)
addy = r.Address
If l1 < l2 Then
MsgBox "You can find happiness in cell " & addy
End If
Next

End Sub

--
Gary''s Student - gsnu201001


"JT" wrote:

I'm looking for a suggestion or code on finding text within a string.

For example, I have a field in an Excel spreadsheet that contains a
description of a user issue.

I want to categorize these descriptions by finding a specific word in the
description, e.g., claim, lawsuit, refund, etc. These specific words are
supposed to appear at the beginning of the description but users may place
them anywhere in the description.

I thought of doing using the 'mid' and cycling through the description but
that doesn't seem to be a very efficient way to validate whether a specific
word appears in the description.

Thanks for the help...


--
JT

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default find text in a string

InStr function???

--
Rick (MVP - Excel)


"Gary''s Student" wrote in message
...
Say we are searching for "happiness". Try this:

Sub FindIt()
Dim s As String
s = "happiness"
For Each r In ActiveSheet.UsedRange
v = r.Value
l = Len(v)
v2 = Application.WorksheetFunction.Substitute(v, s, "")
l2 = Len(v2)
addy = r.Address
If l1 < l2 Then
MsgBox "You can find happiness in cell " & addy
End If
Next

End Sub

--
Gary''s Student - gsnu201001


"JT" wrote:

I'm looking for a suggestion or code on finding text within a string.

For example, I have a field in an Excel spreadsheet that contains a
description of a user issue.

I want to categorize these descriptions by finding a specific word in the
description, e.g., claim, lawsuit, refund, etc. These specific words are
supposed to appear at the beginning of the description but users may
place
them anywhere in the description.

I thought of doing using the 'mid' and cycling through the description
but
that doesn't seem to be a very efficient way to validate whether a
specific
word appears in the description.

Thanks for the help...


--
JT


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
Search, find or lookup defined text in text string zzxxcc Excel Worksheet Functions 9 September 6th 07 09:37 PM
Find text within a string azdps[_4_] Excel Programming 2 August 8th 06 03:10 PM
can you find specific text in a string ignoring any other text chriscp Excel Discussion (Misc queries) 1 September 18th 05 09:54 PM
backwards find function to find character in a string of text Ashleigh K. Excel Programming 1 January 14th 04 04:36 PM
How to Find text in String? Milind Excel Programming 0 September 2nd 03 10:26 PM


All times are GMT +1. The time now is 07:34 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"