Extract Specific Text from String

Ian McPherson

New Member
Joined
Feb 20, 2018
Messages
21
Office Version
  1. 365
Platform
  1. Windows
The below image shows text strings in Col A, and the desired extracted text in col D.
The pattern is shown in bold font and is similar for all strings. All strings are prefixed by '36' except for Mon and Tues.
Thanking you in advance.
1712220661372.png
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
That should do the job:

Book1
AB
2silver gross winner (stroke)36 GROSS STROKE
3silver Tuesday nett winner (stroke)TUE NETT STROKE
4bronze Monday nett winner (sford)MON NETT SFORD
5silver senior gross winner (stroke)36 GROSS STROKE
Sheet1
Cell Formulas
RangeFormula
B2:B5B2=LET(before,{"MON";"TUE"},NG,{"NETT";"GROSS"},SS,{"STROKE";"SFORD"},IFERROR(INDEX(before,MATCH(1,COUNTIF($A2,"*"&before&"*"),0)),36)&" "&INDEX(NG,MATCH(1,COUNTIF($A2,"*"&NG&"*"),0))&" "&INDEX(SS,MATCH(1,COUNTIF($A2,"*"&SS&"*"),0)))
 
Upvote 0
Solution
this is also an option:
Book1
ABCD
1
2SILVER GROSS WINNER(Stroke)36 Gross Stroke
3SILVER GROSS R/U(Stroke)36 Gross Stroke
4SILVER NETT WINNER (Stroke)36 Nett Stroke
5SILVER NETT R/U (Stroke)36 Nett Stroke
6SILVER SENIOR GROSS WINNER (Stroke)36 Gross Stroke
7SILVER SENIOR NETT WINNER (Stroke)36 Nett Stroke
8SILVER TUESDAY NETT WINNER (Stroke)TUE Nett Stroke
9SILVER MONDAY NETT WINNER (Stroke)MON Nett Stroke
10BRONZE NETT WINNER (Sford)36 Nett Sford
11BRONZE NETT R/U (Sford)36 Nett Sford
12BRONZE GROSS WINNER (Sford)36 Gross Sford
13BRONZE GROSS R/U (Sford)36 Gross Sford
14BRONZE SENIOR GROSS WINNER (Sford)36 Gross Sford
15BRONZE SENIOR NET WINNER (Sford)36 Nett Sford
16BRONZE TUESDAY NETT WINNER (Sford)TUE Nett Sford
17BRONZE MONDAY NETT WINNER(Sford)MON Nett Sford
Sheet2
Cell Formulas
RangeFormula
D2:D17D2=LET(theday,MID($A2,8,3),first,IF(OR(theday="TUE",theday="MON"),theday,"36"), middle,IF(ISNUMBER(SEARCH("GROSS",$A2))," Gross "," Nett "),last,TEXTBEFORE(TEXTAFTER($A2,"(",),")"),first&middle&last)
 
Upvote 0
Try this macro code.
Data range= Range("A2:A" & Lr)
VBA Code:
Sub PickBold()
Dim T&, Lr&, temp, Rng As Range, cel As Range, st$

Lr = Range("A" & Rows.Count).End(xlUp).Row

Set Rng = Range("A2:A" & Lr)
Rng.Offset(0, 1).Clear
For Each cel In Rng
st = "": temp = ""
If InStr(1, cel, "MON") = 0 And InStr(1, cel, "TUE") = 0 Then st = "36 " Else st = ""
    For T = 1 To Len(cel)
    If (cel.Characters(T, 1).Font.Bold = True And Mid(cel, T, 1) <> "(" And Mid(cel, T, 1) <> ")") Or Mid(cel, T, 1) = " " Then
    temp = temp & Mid(cel, T, 1)
    End If
Next T
cel.Offset(0, 1) = st & Trim(temp)

Next cel
End Sub
 
Upvote 0
Thank you all - 3 different but accurate solutions.
Cheers
PS I would have used xl2bb to post but the 'Capture Range' always remains invisible.
 
Upvote 0
Working now, thanks for the thread.
Cheers, glad you got it going. (y)

A couple of other formula options.
Col D is a shorter option copied down or Col E is a bit longer but will spill all the results down from a single formula - no need to copy down.

24 04 04.xlsm
ABCDE
1
2SILVER GROSS WINNER(Stroke)36 Gross Stroke36 Gross Stroke
3SILVER GROSS R/U(Stroke)36 Gross Stroke36 Gross Stroke
4SILVER NETT WINNER (Stroke)36 Nett Stroke36 Nett Stroke
5SILVER NETT R/U (Stroke)36 Nett Stroke36 Nett Stroke
6SILVER SENIOR GROSS WINNER (Stroke)36 Gross Stroke36 Gross Stroke
7SILVER SENIOR NETT WINNER (Stroke)36 Nett Stroke36 Nett Stroke
8SILVER TUESDAY NETT WINNER (Stroke)TUE Nett StrokeTUE Nett Stroke
9SILVER MONDAY NETT WINNER (Stroke)MON Nett StrokeMON Nett Stroke
10BRONZE NETT WINNER (Sford)36 Nett Sford36 Nett Sford
11BRONZE NETT R/U (Sford)36 Nett Sford36 Nett Sford
12BRONZE GROSS WINNER (Sford)36 Gross Sford36 Gross Sford
13BRONZE GROSS R/U (Sford)36 Gross Sford36 Gross Sford
14BRONZE SENIOR GROSS WINNER (Sford)36 Gross Sford36 Gross Sford
15BRONZE SENIOR NETT WINNER (Sford)36 Nett Sford36 Nett Sford
16BRONZE TUESDAY NETT WINNER (Sford)TUE Nett SfordTUE Nett Sford
17BRONZE MONDAY NETT WINNER(Sford)MON Nett SfordMON Nett Sford
Extract
Cell Formulas
RangeFormula
E2:E17E2=BYROW(A2:A17,LAMBDA(r,LET(x,MID(r,8,3),IF(OR(x={"Mon","Tue"}),x,36)&" "&IF(ISNUMBER(SEARCH("Nett",r)),"Nett","Gross")&" "&INDEX(TEXTSPLIT(r,{"(",")"}),2))))
D2:D17D2=LET(x,MID(A2,8,3),IF(OR(x={"Mon","Tue"}),x,36)&" "&IF(ISNUMBER(SEARCH("Nett",A2)),"Nett","Gross")&" "&INDEX(TEXTSPLIT(A2,{"(",")"}),2))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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