Finding a word in a sentence

Sindhu

New Member
Joined
Jun 24, 2009
Messages
16
Hii friends,

Good Afternoon...

I have some set of words in excel which i need to search in a sentence. If i find any words of the set in the sentence, then it should be returned.

Eg:
Sentence:
I am poor developer
I am great developer
you may be best developer

Lookup(Set of key words):
great
poor
best

Expected o/p:

I am poor developer poor
I am great developer great
you may be best developer best

Can anyone help me out to find a solution for this problem.?




Thanks in Advance
Sindhu
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
With sentences in A2:A4, and keywords in A7:A9, try this macro. Adjust ranges as needed.

Code:
Option Explicit
Sub Sindhu()
Dim i As Integer
Dim r As Range
Dim v

v = Application.Transpose(Range("A7:A9"))

For i = LBound(v) To UBound(v)
    With ActiveSheet.Range("A2:A4")

        On Error Resume Next
        Set r = .Find(What:=v(i), After:=.Cells(.Cells.Count), LookIn:=xlFormulas, LookAt:=xlPart, _
                      SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
        On Error GoTo 0

        If Not r Is Nothing Then
            r = r.Value & " " & v(i)
        End If

        Set r = Nothing

    End With
Next i

End Sub


HTH!
 
Upvote 0

Forum statistics

Threads
1,214,374
Messages
6,119,159
Members
448,870
Latest member
max_pedreira

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top