Find a word within a sentence

RoseChapman

New Member
Joined
Jun 12, 2018
Messages
39
Hello,

I have a problem using VBA and I would really appreciate if someone could help.

I am using the following code to find the word "house" in any cell within column "L", if the word "house" is found within a sentence in a cell within column L copy whatever is in columns A, L and BX and paste them in another tab called "Paste".
My problem is I do not know how to add "find a sentence containing the word "house"" to the code. Could you please help me?. Many thanks. Rose

Sub Filtering()


Dim Lastrow As Long


With Sheets("Sheet1")

If .Range("L:L").Find("House", , xlValues, xlWhole, , , False) Is Nothing Then
MsgBox "No ""Changed"" rows found. ", , "No Rows Copied": Exit Sub
End If

Application.ScreenUpdating = False
Lastrow = .Range("BY" & Rows.Count).End(xlUp).Row
.Range("A1:BY" & Lastrow).AutoFilter Field:=76, Criteria1:="House"
Intersect(.AutoFilter.Range, .Range("A:A, L:L, BX:BX")).Copy

Sheets("Paste").Range("A:R").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False
.AutoFilterMode = False


With Application
.CutCopyMode = False
.Goto Sheets("Outputs").Range("A:BX")
.ScreenUpdating = True
End With

End With
End Sub
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

davesexcel

Well-known Member
Joined
Feb 26, 2006
Messages
1,089
A bit confusing, you originally say you want to search column L for the word house, but your code is searching Column 76.

A single line of code will filter column L for the word "House"

Code:
    Range("A1").AutoFilter Field:=12, Criteria1:="=*House*", Operator:=xlAnd
 

RoseChapman

New Member
Joined
Jun 12, 2018
Messages
39
Hi Dave,
Thanks for you help. sorry, I tried the code you provided and it does not work.
76 means looking at columns from A to BX. I have used the code you provided with Field=12, but it does not work..
Any other suggestion, please?
Thanks
 

davesexcel

Well-known Member
Joined
Feb 26, 2006
Messages
1,089
Yep, you said you wanted to find House in column L, column L is 12, not 76
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,384
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

76 means looking at columns from A to BX.
This
Code:
.Range("A1:BY" & Lastrow).AutoFilter Field:=76, Criteria1:="House"
Is filtering on col BX only, not all the columns from A to BX.

Which column do you want to look at?
 
Last edited:

RoseChapman

New Member
Joined
Jun 12, 2018
Messages
39
Ah, ok! I have amended it, but this is still not doing the work. Any suggestion please?. Many thanks

Application.ScreenUpdating = False
Lastrow = .Range("BY" & Rows.Count).End(xlUp).Row
.Range("A1:BY" & Lastrow).AutoFilter Field:=12, Criteria1:="House"
Intersect(.AutoFilter.Range, .Range("A:A, L:L, BX:BX")).Copy

Sheets("Paste").Range("A:R").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False
.AutoFilterMode = False


With Application
.CutCopyMode = False
.Goto Sheets("Outputs").Range("A:BX")
.ScreenUpdating = True
End With
 

RoseChapman

New Member
Joined
Jun 12, 2018
Messages
39

ADVERTISEMENT

I want to find the word "House" in sentences within column L, for example If the sentence"This house is beautiful" is in cell L30, then copy what is in columns A30, L30 and BX30 and paste it in another tab in columns A1, B1, C1. This is what I would like the code to do. Many thanks
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,384
Office Version
  1. 365
Platform
  1. Windows
Try
Code:
.Range("A1:BY" & LastRow).AutoFilter 12, "*House*"
BUT this will also find words such as Houseboat, Housemate etc
 

RoseChapman

New Member
Joined
Jun 12, 2018
Messages
39
Hello!. This works now!, it does the job as I needed! great stuff Mr.Excel and all!
Many thanks once more!
 

Watch MrExcel Video

Forum statistics

Threads
1,123,504
Messages
5,602,057
Members
414,498
Latest member
jordanmiller7890

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
Top