Extracting 2 or 3 words before a match found

satish78

Board Regular
Joined
Aug 31, 2014
Messages
218
Hi Friends,

I tried to extract first 2 words using this =TRIM(RIGHT(A1, FIND(B1",SUBSTITUTE(A1, " ", B1,2)&B1)))
below is the text in ColumnA

A1=Refresh staging database use data pump
B1=Data
C1= =TRIM(RIGHT(A1, FIND(B1",SUBSTITUTE(A1, " ", B1,2)&B1)))
some how did not work

Can anyone let me know where I been wrong?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try this:
=TRIM(LEFT(A1,SEARCH(B1,A1)-1))
 
Last edited:
Upvote 0
Hi Friends,

I tried to extract first 2 words using this =TRIM(RIGHT(A1, FIND(B1",SUBSTITUTE(A1, " ", B1,2)&B1)))
below is the text in ColumnA

A1=Refresh staging database use data pump
B1=Data
C1= =TRIM(RIGHT(A1, FIND(B1",SUBSTITUTE(A1, " ", B1,2)&B1)))
some how did not work

Can anyone let me know where I been wrong?
Did you want to match "data" in "database" or the free-standing "data" toward the end of the text?
 
Upvote 0
Hi,

So is the correct result in your sample "Refresh staging" or "database use"?
 
Upvote 0
Rick.

only "data" I need to look.
Assuming the word "data" has only space characters next to it (unless it is at the end of the text in which case it has only a space character in front of it), give this formula a try...

=TRIM(LEFT(RIGHT(SUBSTITUTE(TRIM(LEFT(A1,SEARCH(" "&B1&" "," "&A1&" ")-1))," ",REPT(" ",300)),600),600))
 
Upvote 0
Hi,

So is the correct result in your sample "Refresh staging" or "database use"?

If it's the latter, you can also try this:


Book1
ABG
1Refresh staging database use data pumpDatadatabase use
Sheet29
Cell Formulas
RangeFormula
G1=TRIM(RIGHT(SUBSTITUTE(LEFT(A1,SEARCH(" "&B1&" ",A1)-1)," ",REPT(" ",250)),500))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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