Formula to find all text before a given word

Abhishek1988

New Member
Joined
Oct 22, 2018
Messages
27
Hi Everyone,

I need help in excel. Please find below for example:
ABCD
1Vikas Agarwal John Monty
2Parul sharma Brown Peter Chris
3
4

<tbody>
</tbody>

i want to take all words mentioned before John/Peter. so my B1 should be Vikas Agarwal and B2 should be Parul sharma Brown.

please help
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Are John and Peter ( or any other search string) always the second last word in the string?
 
Upvote 0
No it could be anything.. I just made this but not able to put under multiple conditions

=TRIM(LEFT(A1, SEARCH(G5,A1)-1))

G5 - John

But i want to apply this to multiple condition. if G6 is Peter how can u put the same in above?
 
Upvote 0
My question is : is the string to be searched ALWAYS the second last in the entire string?
 
Upvote 0
You can modify this formula to meet your requirement :

=TRIM(LEFT(A1,FIND(G1,A1,1)-2))
 
Upvote 0
No it could be different.

Name could be Alex Harmer John Michael Hughes. I want to text before John or peter (as per my question) no matter wherever they are placed
 
Upvote 0
=IFERROR(TRIM(LEFT(A1,LOOKUP(9.99999999E+307,SEARCH({"John","Peter"},A1))-1)),"")


Excel 2010
AB
1Vikas Agarwal John MontyVikas Agarwal
2Parul sharma Brown Peter ChrisParul sharma Brown
Sheet1
Cell Formulas
RangeFormula
B1=IFERROR(TRIM(LEFT(A1,LOOKUP(9.99999999E+307,SEARCH({"John","Peter"},A1))-1)),"")
B2=IFERROR(TRIM(LEFT(A2,LOOKUP(9.99999999E+307,SEARCH({"John","Peter"},A2))-1)),"")
 
Upvote 0

Forum statistics

Threads
1,215,445
Messages
6,124,894
Members
449,194
Latest member
JayEggleton

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