Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
find and replace numeric strings in larger text strings | Excel Worksheet Functions | |||
Finding 1 of 3 different strings in a string | Excel Worksheet Functions | |||
Finding 13 character codes in text strings | Excel Worksheet Functions | |||
How to find number of pairs of strings from list of strings? | Excel Worksheet Functions | |||
Finding strings within strings | Excel Programming |