I want to extract a substring from a cell in a column based on search match

andrebooyzen

New Member
Joined
May 30, 2023
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi All.
Great forum.
I have a column of data and I want to search the whole column for a match to name and then extract the first 5 characters from the cell that has a match. I have triend INDEX and MATCH and VLOOKUP with varying results.
Please help :)
Thanks

Typical cell in the column looks like this

09:00-10h30
Andre
Peter

I want to search all the cells in a specified column for a name eg Peter, and if it finds a match then return the first 5 characters of the cell.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi @andrebooyzen.
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.​

Try this formula:
Dante Amor
ABCDE
1match to name
2Peter
3
409:00-10h30 Andre Peter09:00
509:00-10h30 Sm John 
609:00-10h30 Wa Peter09:00
Hoja4
Cell Formulas
RangeFormula
C4:C6C4=IF(ISNUMBER(SEARCH($E$2,B4)),LEFT(B4,5),"")


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0
Thanks a lot Dante. That will work perfectly if searching one cell. But I want to search the whole column until it finds a match for Peter and then extract the first 5 characters from the cell it matched with.
Appreciate your help.
 
Upvote 0
Thanks a lot Dante. That will work perfectly if searching one cell. But I want to search the whole column until it finds a match for Peter and then extract the first 5 characters from the cell it matched with.
Appreciate your help.
I want to do this as a straight excel formula
 
Upvote 0
Welcome to the MrExcel board!

For the future, I suggest that you investigate XL2BB for providing sample data & expected results to make it easier for helpers to understand just what you have & where it is and also what you want & where it is to be.

See if this is headed in the right direction

23 05 31.xlsm
ABC
1
211:30-12h30 Andre Pedro
309:00-10h30 Simon John
409:00-10h30 Wayne Peter
5
6
7
8NameTime
9Peter09:00
10Andre11:30
11Ken 
12Wayne09:00
Match
Cell Formulas
RangeFormula
C9:C12C9=LET(x,XLOOKUP("*"&B9&"*",B$2:B$4,B$2:B$4,"",2),IF(x="",x,LEFT(x,5)+0))
 
Upvote 0
Try:

varios 30may2023.xlsm
ABCDE
1match to name
2peter09:00
3
406:00-10h30 Fi Sue
508:00-10h30 Sm John
609:00-10h30 Wa Peter
Hoja4
Cell Formulas
RangeFormula
E2E2=IFERROR(LEFT(INDEX(B4:B6,MATCH("*"&D2&"*",B4:B6,0)),5),"Not exists")
 
Upvote 0
Solution
See if this is headed in the right direction
If you don't need the result as an actual time (number) then the version of my suggestion would be

23 05 31.xlsm
ABC
1
211:30-12h30 Andre Pedro
309:00-10h30 Simon John
409:00-10h30 Wayne Peter
5
6
7
8NameTime
9Peter09:00
10Andre11:30
11Ken 
12Wayne09:00
Match (2)
Cell Formulas
RangeFormula
C9:C12C9=LET(r,B$2:B$4,LEFT(XLOOKUP("*"&B9&"*",r,r,"",2),5))
 
Upvote 0
Also try the following:

Dante Amor
ABCDE
1match to name
2peter09:00
3
406:00-10h30 Fi Sue
508:00-10h30 Sm John
609:00-10h30 Wa Peter
Hoja4
Cell Formulas
RangeFormula
E2E2=LEFT(VLOOKUP("*"&D2&"*",B4:B6,1,0),5)
 
Upvote 0
=LET(x,XLOOKUP("*"&B9&"*",B$2:B$4,B$2:B$4,"",2),IF(x="",x,LEFT(x,5)+0))
Thanks Peter and for the welcome.
It found 2 matches correctly in the column I searched. However it returned a 1 in one match and a 0 in the other match.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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