Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Finding strings within strings


Hello everyone

Can anyone help me to determine how to do this: I need to write a macro that will search certain cell to find specific strings that cell *may* contain. For example, say I would like to know exacly what fruits from the group {"apples," "bananas," and "pears"} are listed in each cell. Then, if a cell contains the text "Today I had apples for lunch," or "Yesterday I had pears for lunch," the macro would return "apples" or "pears," respectively

Any clue? Thank you very much in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Finding strings within strings

One way:

Public Function CheckForFruit(ByVal rCell As Range) As String
Dim vFruits As Variant
Dim i As Long
vFruits = Array("apples", "bananas", "pears")
For i = 0 To UBound(vFruits)
If InStr(rCell, vFruits(i)) Then
CheckForFruit = vFruits(i)
Exit For
End If
Next i
End Function

In article ,
Rod wrote:

Hello everyone!

Can anyone help me to determine how to do this: I need to write a macro that
will search certain cell to find specific strings that cell *may* contain.
For example, say I would like to know exacly what fruits from the group
{"apples," "bananas," and "pears"} are listed in each cell. Then, if a cell
contains the text "Today I had apples for lunch," or "Yesterday I had pears
for lunch," the macro would return "apples" or "pears," respectively.

Any clue? Thank you very much in advance.

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 and replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
Finding 1 of 3 different strings in a string MarkMcG Excel Worksheet Functions 3 June 10th 08 05:55 PM
Finding 13 character codes in text strings Bhupinder Rayat Excel Worksheet Functions 2 April 25th 06 05:14 PM
How to find number of pairs of strings from list of strings? greg_overholt Excel Worksheet Functions 5 January 27th 06 10:42 PM
Finding strings within strings Rod[_6_] Excel Programming 1 December 2nd 03 05:19 PM


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