Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Point Me. Searching strings for lists of keywords

How would you go about this? Column of cells of text. I want to seach each cell for a list of words and, if a word is found, put a value in a cell. Example. If text contains any of the words Chevy, Buick, Caddilac, i'd like to out that word in an ajacent cell for indexing purposes. The list of words will be pretty long so nested if's are not a good approach. Thanks for any suggestions.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Point Me. Searching strings for lists of keywords

One way:

Public Sub ExtractForIndex()
Dim vKeyWords As Variant
Dim rCell As Range
Dim rFound As Range
Dim i As Long
Dim sFoundAddr As String

vKeyWords = Array("Chevy", "Buick", "Cadillac")
With Columns(1).Cells
For i = 0 To UBound(vKeyWords)
Set rFound = .Find( _
What:=vKeyWords(i), _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=False)
If Not rFound Is Nothing Then
sFoundAddr = rFound.Address
Do
rFound.Offset(0, 1).Value = vKeyWords(i)
Set rFound = .FindNext(After:=rFound)
Loop Until rFound.Address = sFoundAddr
End If
Next i
End With
End Sub

Note: This assumes only one keyword per cell. If multiple keywords
are in a cell, only the last will be listed. If that's the case and
you need assistance in modifying the macro, post back.



In article ,
"Brad" wrote:

How would you go about this? Column of cells of text. I want to seach each
cell for a list of words and, if a word is found, put a value in a cell.
Example. If text contains any of the words Chevy, Buick, Caddilac, i'd like
to out that word in an ajacent cell for indexing purposes. The list of words
will be pretty long so nested if's are not a good approach. Thanks for any
suggestions.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Point Me. Searching strings for lists of keywords

Here's another approach using Match:

Sub Lookfor()
Dim cell As Range, res As Variant
For Each cell In Range("A1:A25")
res = Application.Match(cell.Value, _
Array("Chevy", "Buick", "Cadillac"), 0)
If Not IsError(res) Then
cell.Offset(, 1).Value = cell.Value
End If
Next
End Sub


"Brad" wrote in message
...
How would you go about this? Column of cells of text. I want to seach

each cell for a list of words and, if a word is found, put a value in a
cell. Example. If text contains any of the words Chevy, Buick, Caddilac,
i'd like to out that word in an ajacent cell for indexing purposes. The
list of words will be pretty long so nested if's are not a good approach.
Thanks for any suggestions.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Point Me. Searching strings for lists of keywords

I think I misunderstood your post.

"Tim Zych" wrote in message
...
Here's another approach using Match:

Sub Lookfor()
Dim cell As Range, res As Variant
For Each cell In Range("A1:A25")
res = Application.Match(cell.Value, _
Array("Chevy", "Buick", "Cadillac"), 0)
If Not IsError(res) Then
cell.Offset(, 1).Value = cell.Value
End If
Next
End Sub


"Brad" wrote in message
...
How would you go about this? Column of cells of text. I want to seach

each cell for a list of words and, if a word is found, put a value in a
cell. Example. If text contains any of the words Chevy, Buick, Caddilac,
i'd like to out that word in an ajacent cell for indexing purposes. The
list of words will be pretty long so nested if's are not a good approach.
Thanks for any suggestions.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Point Me. Searching strings for lists of keywords

It would be of great help to me, if you could demonstate
the technique for the situation where multiple keywords
could exist within the same cell.

Regards.

"J.E. McGimpsey" wrote in message
...
One way:

Public Sub ExtractForIndex()
Dim vKeyWords As Variant
Dim rCell As Range
Dim rFound As Range
Dim i As Long
Dim sFoundAddr As String

vKeyWords = Array("Chevy", "Buick", "Cadillac")
With Columns(1).Cells
For i = 0 To UBound(vKeyWords)
Set rFound = .Find( _
What:=vKeyWords(i), _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=False)
If Not rFound Is Nothing Then
sFoundAddr = rFound.Address
Do
rFound.Offset(0, 1).Value = vKeyWords(i)
Set rFound = .FindNext(After:=rFound)
Loop Until rFound.Address = sFoundAddr
End If
Next i
End With
End Sub

Note: This assumes only one keyword per cell. If multiple keywords
are in a cell, only the last will be listed. If that's the case and
you need assistance in modifying the macro, post back.



In article ,
"Brad" wrote:

How would you go about this? Column of cells of text. I want to seach

each
cell for a list of words and, if a word is found, put a value in a cell.
Example. If text contains any of the words Chevy, Buick, Caddilac, i'd

like
to out that word in an ajacent cell for indexing purposes. The list of

words
will be pretty long so nested if's are not a good approach. Thanks for

any
suggestions.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.548 / Virus Database: 341 - Release Date: 05/12/2003




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Point Me. Searching strings for lists of keywords

One way:

To put all the terms into one cell, replace the Do...Loop with:

Do
With rFound.Offset(0, 1)
.Value = IIf(IsEmpty(.Value), "", _
.Text & ", ") & vKeyWords(i)
End With
Set rFound = .FindNext(After:=rFound)
Loop Until rFound.Address = sFoundAddr

To put applicable terms into adjoining cells, replace the do loop
with:

Do
With rFound.Offset(0, 1).Resize(
1, UBound(vKeyWords))
.Item(Application.CountA(.Cells) + _
1).Value = vKeyWords(i)
End With
Set rFound = .FindNext(After:=rFound)
Loop Until rFound.Address = sFoundAddr

In article ,
"Stuart" wrote:

It would be of great help to me, if you could demonstate
the technique for the situation where multiple keywords
could exist within the same cell.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Point Me. Searching strings for lists of keywords

Many thanks for that. I'm hoping to adapt the routine so as to
build 3 arrays to hold all found instances of the keywords,
and then to copy them to a new workbook.

Regards.

"J.E. McGimpsey" wrote in message
...
One way:

To put all the terms into one cell, replace the Do...Loop with:

Do
With rFound.Offset(0, 1)
.Value = IIf(IsEmpty(.Value), "", _
.Text & ", ") & vKeyWords(i)
End With
Set rFound = .FindNext(After:=rFound)
Loop Until rFound.Address = sFoundAddr

To put applicable terms into adjoining cells, replace the do loop
with:

Do
With rFound.Offset(0, 1).Resize(
1, UBound(vKeyWords))
.Item(Application.CountA(.Cells) + _
1).Value = vKeyWords(i)
End With
Set rFound = .FindNext(After:=rFound)
Loop Until rFound.Address = sFoundAddr

In article ,
"Stuart" wrote:

It would be of great help to me, if you could demonstate
the technique for the situation where multiple keywords
could exist within the same cell.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.548 / Virus Database: 341 - Release Date: 05/12/2003


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
Searching for strings in a column [email protected] Excel Worksheet Functions 6 January 23rd 09 06:20 PM
Is there a formula for searching for any one of a list of strings? bookgirl Excel Worksheet Functions 8 December 1st 06 06:55 PM
Searching for codes in text strings Bhupinder Rayat Excel Worksheet Functions 9 April 27th 06 01:20 PM
Searching for Substrings Within Strings Tiziano Excel Discussion (Misc queries) 8 January 6th 05 03:09 AM


All times are GMT +1. The time now is 03:17 PM.

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"