Extract Strings which hyphen in the code

rikkiw

New Member
Joined
Mar 11, 2024
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hello there, I have below column that I want to extract the strings with hyphen on the room code, can anyone help here? Many Thanks!

For example here, I want to add a column and export all the FM numbers from Description, such as FM1-325, FM8-525, FM2-710 ect....

NumberDescription
1000000LEAKING VALVE ON BOILERS
1000001FM1-325 LEAK
1000002SINK FM8-525
1000003SINKS FM2-710 2
1000004FM5-807 FR STERI
1000005STUCK FM5-816 SINK
1000006LEAKING FM2-412
1000007FM4-606 TOILET
1000008FM5-816-SINK
1000009WALL FM7-508
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Will the strings always be the same length and format (FM#-###) ? If so, perhaps this:
Book1
ABC
1NumberDescription
21000000LEAKING VALVE ON BOILERS 
31000001FM1-325 LEAKFM1-325
41000002SINK FM8-525FM8-525
51000003SINKS FM2-710 2FM2-710
61000004FM5-807 FR STERIFM5-807
71000005STUCK FM5-816 SINKFM5-816
81000006LEAKING FM- 
91000007FM4-606 TOILETFM4-606
101000008FM5-816-SINKFM5-816
111000009WALL FM7-508FM7-508
Sheet1
Cell Formulas
RangeFormula
C2:C11C2=IFERROR(MID(B2,SEARCH("FM?-",B2),7),"")
 
Last edited:
Upvote 0
Hello Dreid, thank you so much for replying.

Unfortunate there is not only FMX-XXX code, there is also TX-XXX, TX-XXXX ect.... Just now I also noted that there are also code like FMXXXX. So looks like no formal pattern, but I think extracting FMX-XXX, TX-TTT should be sufficient...
 
Upvote 0
Perhaps this then until something better comes along:
Book1
ABC
1NumberDescription
21000000LEAKING VALVE ON BOILERS 
31000001FM1-325 LEAKFM1-325
41000002SINK T8-525T8-525
51000003SINKS FM2-710 2FM2-710
61000004FM5-807 FR STERIFM5-807
71000005STUCK FM5-816 SINKFM5-816
81000006LEAKING FM- 
91000007FM4-606 TOILETFM4-606
101000008FM5-816-SINKFM5-816
111000009WALL FM7-508FM7-508
Sheet1
Cell Formulas
RangeFormula
C2:C11C2=IFERROR(MID(B2,SEARCH("FM?-",B2),7),"")&IFERROR(MID(B2,SEARCH("T?-",B2),6),"")
 
Upvote 0
Thank you, and you're welcome. I am still going to play with it to see if I can get something a little bit more inclusive.
 
Upvote 0
Okay, this should be a little bit more inclusive. I can't guarantee you won't get some undesired results occasionally, but worth a shot:
Book1
ABC
1NumberDescription
21000000LEAKING VALVE ON BOILERS 
31000001FM1-325 LEAKFM1-325
41000002SINK T8-5254T8-5254
51000003SINKS FM2710 2FM2710
61000004FM5-807 FR STERIFM5-807
71000005STUCK FM5-816 SINKFM5-816
81000006LEAKING T5-444T5-444
91000007FM4-606 TOILETFM4-606
101000008FM5-816-SINKFM5-816
111000009WALL FM7-508FM7-508
Sheet1
Cell Formulas
RangeFormula
C2:C11C2=TEXTBEFORE(SUBSTITUTE(SUBSTITUTE(TEXTAFTER(SUBSTITUTE(B2,"FM","@FM"),"@",,,,"")&" "," ","@"),"-","@",2),"@",1)&IFERROR(TRIM(MID(B2,SEARCH("T?-",B2),7)),"")
 
Upvote 0
This is the only item that doesn't match the formats of the other ones. Is there supposed to be a - hyphen before SINK?
FM5-816-SINK
 
Upvote 0
If so,
=TRIM(LEFT(SUBSTITUTE(LET(t,TEXTSPLIT(B2&" "," "),FILTER(t,ISNUMBER(SEARCH("-",t)),"")),"-",REPT(" ",255),2),255))

If not,
=LET(t,TEXTSPLIT(B2&" "," "),FILTER(t,ISNUMBER(SEARCH("-",t)),""))
 
Upvote 0
Okay, this should be a little bit more inclusive. I can't guarantee you won't get some undesired results occasionally, but worth a shot:
Book1
ABC
1NumberDescription
21000000LEAKING VALVE ON BOILERS 
31000001FM1-325 LEAKFM1-325
41000002SINK T8-5254T8-5254
51000003SINKS FM2710 2FM2710
61000004FM5-807 FR STERIFM5-807
71000005STUCK FM5-816 SINKFM5-816
81000006LEAKING T5-444T5-444
91000007FM4-606 TOILETFM4-606
101000008FM5-816-SINKFM5-816
111000009WALL FM7-508FM7-508
Sheet1
Cell Formulas
RangeFormula
C2:C11C2=TEXTBEFORE(SUBSTITUTE(SUBSTITUTE(TEXTAFTER(SUBSTITUTE(B2,"FM","@FM"),"@",,,,"")&" "," ","@"),"-","@",2),"@",1)&IFERROR(TRIM(MID(B2,SEARCH("T?-",B2),7)),"")
Tried this one and it did work much better than the first one, capturing more values now! Much appreciated:) (y)
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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