Extract Specific Character Formats from a Text String

Excel2021

New Member
Joined
Mar 26, 2021
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I am trying to extract anything that comes after a hypen and has the following format character format "A123" from a Text String in power query (an excel formula would also work). Occasionally some of the formats I need to pull may vary and contain the format "AA123" or "AA123-AA".

String examples of each type are below in quotes and what I would like to pull is after the = on the right of the strings.

"GBS-1S-65-X555-7" = X555
"MRK-4S-95-XX555-7" = XX555
"KLS-5S-38-X555-UV" = X555-UV

Thanks in Advance.
 
Second try, now I (maybe) understand the query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Combine(List.Select(List.LastN(Text.Split([Column1],"-"),2), each (try Number.FromText(_) otherwise  true) = true),"-"))
in
    #"Added Custom"

Book1
BCDEFGHIJKL
1Column1Column1Custom
2GBS-1S-65-X555-7GBS-1S-65-X555-7X555
3MRK-4S-95-XX555-7MRK-4S-95-XX555-7XX555
4KLS-5S-38-X555-UVKLS-5S-38-X555-UVX555-UV
5KLS-5S-38-X555KLS-5S-38-X555X555
6KLS-5S-38-UV-X555KLS-5S-38-UV-X555UV-X555
7
8
9
Sheet1
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi
An excel worksheet solution for above.
=MID(A1,FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1)+1,20)
Thanks
Waseem
 

Attachments

  • MrExcelAnswer1.png
    MrExcelAnswer1.png
    11.6 KB · Views: 7
Upvote 0
Hi
An excel worksheet solution for above.
=MID(A1,FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1)+1,20)
Thanks
Waseem
That's not what the OP described as correct in #7: B1 result should be X555 only, hence not including "-7" in the string.
 
Upvote 0
Hi
I correct myself. This worksheet formula would do :
=MID(A1,D1+1,FIND("-",A1,FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1)+1)-1-FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1))
Thanks
 
Upvote 0
Hi
I correct myself. This worksheet formula would do :
=MID(A1,D1+1,FIND("-",A1,FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1)+1)-1-FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1))
Thanks
Hi Waseem,

What's in D1 in your solution?
Please use XL2BB code (download link in my signature), so we see the sample data and any parameters you've defined inside cells.
Simply using your formula, returns very odd results.
Book1
CDEFGH
1Column1Custom
2GBS-1S-65-X555-7X555X555-7GBS-
3MRK-4S-95-XX555-7XX555XX555-7MRK-4
4KLS-5S-38-X555-UVX555-UVX555-UVKLS-
5KLS-5S-38-X555X555X555#VALUE!
6KLS-5S-38-UV-X555UV-X555UV-X555KL
7
Sheet1
Cell Formulas
RangeFormula
F2:F6F2=MID(D2,FIND("-",D2,FIND("-",D2,FIND("-",D2,1)+1)+1)+1,20)
G2:G6G2=MID(D2,C2+1,FIND("-",D2,FIND("-",D2,FIND("-",D2,FIND("-",D2,1)+1)+1)+1)-1-FIND("-",D2,FIND("-",D2,FIND("-",D2,1)+1)+1))
 
Upvote 0
Hi
Please find below :
=MID(A1,FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1)+1,FIND("-",A1,FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1)+1)-1-FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1))
Thanks
 
Upvote 0
Second try, now I (maybe) understand the query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Combine(List.Select(List.LastN(Text.Split([Column1],"-"),2), each (try Number.FromText(_) otherwise  true) = true),"-"))
in
    #"Added Custom"

Book1
BCDEFGHIJKL
1Column1Column1Custom
2GBS-1S-65-X555-7GBS-1S-65-X555-7X555
3MRK-4S-95-XX555-7MRK-4S-95-XX555-7XX555
4KLS-5S-38-X555-UVKLS-5S-38-X555-UVX555-UV
5KLS-5S-38-X555KLS-5S-38-X555X555
6KLS-5S-38-UV-X555KLS-5S-38-UV-X555UV-X555
7
8
9
Sheet1
Sorry, I was tied up with other things the past few days. I tried this however I am getting a similar issue where it will only take the UV for some of the strings and ignore the rest.
 
Upvote 0
Hi
Please find below :
=MID(A1,FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1)+1,FIND("-",A1,FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1)+1)-1-FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1))

Hi
Please find below :
=MID(A1,FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1)+1,FIND("-",A1,FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1)+1)-1-FIND("-",A1,FIND("-",A1,FIND("-",A1,1)+1)+1))
Thanks
Hi,

I tried this but I am getting similar results to the power query ones where it seems to have issues with the "UV" parts. I will post a better list of strings. Maybe I am missing some variations.
 
Upvote 0
Like I said before, if you want better solutions you have to post more examples with desired outcomes
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,612
Members
449,109
Latest member
Sebas8956

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