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:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Vikas Agarwal John Monty[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Parul sharma Brown Peter Chris[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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