Extract text from middle of string using character count

rythmic_flow

New Member
Joined
Jan 16, 2019
Messages
17
Hello,

I would like to extract the name only from a cell that comes through in the following format:

abc123456789 JOE BLOGGS abc123456789

The name can very in length, but the number of characters from the far left and far right of the string always stay the same amount.

Is there a formula that can count characters both from the right and from the left and extract what is in the middle?

Or are any different ways to do this?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
if the name is always in upper case and the rest is in lower case
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],
    Result = Table.RemoveColumns(Table.TransformColumns(Table.AddColumn(Source, "Name", each Text.Select([raw], {"A".."Z", " "})),{{"Name", Text.Trim, type text}}),{"raw"})
in
    Result
rawName
abc123456789 JOE BLOGGS abc123456789JOE BLOGGS
 
Upvote 0
Hi Alpha,

This works for the above sample, but doesn't cover the varying lengths of names.

If the number of characters before and after the name are always a consistent amount, is there a formula that can trim both the first 13 and last 13 characters from a cell?
 
Upvote 0
if the name is always in upper case and the rest is in lower case
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],
    Result = Table.RemoveColumns(Table.TransformColumns(Table.AddColumn(Source, "Name", each Text.Select([raw], {"A".."Z", " "})),{{"Name", Text.Trim, type text}}),{"raw"})
in
    Result
rawName
abc123456789 JOE BLOGGS abc123456789JOE BLOGGS
That's a good suggestion, but unfortunately there are variables here too
 
Upvote 0
but unfortunately there are variables here too
you didn't say that in post#1 and it seems your example is not representative
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],
    TBD = Table.AddColumn(Source, "Result", each Text.BetweenDelimiters([raw], " ", " ", 0, 1), type text),
    TSC = Table.SelectColumns(TBD,{"Result"})
in
    TSC
result is the same as above
 
Upvote 0
you didn't say that in post#1 and it seems your example is not representative
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],
    TBD = Table.AddColumn(Source, "Result", each Text.BetweenDelimiters([raw], " ", " ", 0, 1), type text),
    TSC = Table.SelectColumns(TBD,{"Result"})
in
    TSC
result is the same as above

Thanks for pointing it out. I can't seem to find an edit function to change my original post, but will bear in mind next time.

Regarding your latest formula, is this something that needs to be done within powerquery? I don't have experience with this. Is there a more simple formula using TRIM/MID/LEN function?

A more accurate example would be:

abC-123456789 JOE BLOGGS aBC123456789

Variables: Length of name can change

Consistencies: Number of characters before and after name will be the same each time
 
Upvote 0
Sandy, looking back at your posts, i'm seeing both your formulas in power query coding now. I don't know what has changed or why i am seeing like this?
 
Upvote 0
first code extracting upper case letter and spaces then trim which is wrong because of post#5
second code extracting string between space before name and space after name
it doesn't count anything
both are M (Power Query)
 
Upvote 0
Hi Alpha,

This works for the above sample, but doesn't cover the varying lengths of names.

If the number of characters before and after the name are always a consistent amount, is there a formula that can trim both the first 13 and last 13 characters from a cell?

=MID(A1,14,LEN(A1)-26)

The formula trims both the first 13 and last 13 characters from a cell regardless of the length of name in between.

What am I missing? Did you try it?
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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